【发布时间】: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