ERR_EMPTY_RESPONSE 下载生成的 zip

ERR_EMPTY_RESPONSE on downloading generated zip

所以我试图生成一个包含一堆 pdf 的 zip 文件。

一段时间后我开始工作了,但服务器出现问题 ERR_EMPTY_RESPONSE。

这是代码:

<?php
$file_names=$pdfs; //This is an array of names of files in PDF format: 1.pdf, 2pdf, 3pdf...


$zip = new ZipArchive;
$zip_name = ("test.zip");
$path_zip = ("C:/www/test/docs/");
$zip->open($path_zip.$zip_name,ZipArchive::CREATE);

foreach ($file_names as $file) {
    $zip->addFile($file,basename($file));
}

$zip->close();

//then send the headers to force download the zip file

header("Content-type: application/zip"); 
header("Content-Disposition: attachment; filename=$zip_name"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
@readfile($path_zip.$zip_name);
exit;
?>

这些 PDF 是以前使用其他代码从互联网上下载的

我该如何解决这个问题?

编辑::

正在添加显示 zip 的图像。

编辑 2:: 我删除了最后一行的 @ 并进行了测试。没有任何效果。

所以...

它很丑,但它有效...

我刚换了

header("Content-type: application/zip"); 
header("Content-Disposition: attachment; filename=$zip_name"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
readfile($path_zip.$zip_name);
exit;

为了

header("Location: ".$path_zip.$zip_name);

正如我所说,它非常丑陋,但它确实有效,它让用户下载文件并且不会卡住或类似的问题。

如果有人想做另一个真正的修复,我会测试它,因为我不想改变位置。

再见。