【问题标题】:Laravel zipArchive throws Site can't be reachedLaravel zipArchive 抛出站点无法访问
【发布时间】:2018-11-22 08:37:29
【问题描述】:

我正在尝试下载 pdf 文件并使用 ZipArchive 对其进行压缩。但它给了我“无法访问此站点”错误..

这是我的代码:

$zip = new \ZipArchive();
$archive_file_name = date('YmdHis') . '.zip';

if ($zip->open($archive_file_name, $zip::CREATE) !== true) {
    exit("cannot open <$archive_file_name>\n");
}

foreach ($Contracts as $Contract) {

    if (!$Contract->parent_id) {
        $template = $request->template;
    } else {
        $template = $request->template_amendment;
    }

    $pdf = $Contract->getPdfPath($template);

    /** @var \Dompdf\Dompdf $dompdf */
    if (!$pdf && $dompdf = $Contract->generatePdf(true, true, $template)) $pdf = $dompdf->path;

    $ContractPdf = \App\Models\ContractPdf::where('contract_id', $Contract->id)->where('pdf_template', $template)->orderBy('created_at', 'desc')->first();
    $unprotected = str_replace($ContractPdf->pdf_filename, 'unprotected/' . $ContractPdf->pdf_filename, $pdf);

    if ($unprotected && file_exists($unprotected)) $pdf = $unprotected;

    $zip->addFile($Storage->url($pdf), $ContractPdf->pdf_filename);

}

$zip->close();

//then send the headers to force download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;

问题出在我的代码中还是在本地设置中?以及如何解决?

【问题讨论】:

    标签: php laravel laravel-5.4 ziparchive


    【解决方案1】:

    结案!

    我是多么愚蠢!我应该将$pdf 放入addFile() 参数而不是$Storage-&gt;url($pdf)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 2012-12-26
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多