所以我試圖生成一個包含一堆 pdf 的 zip 檔案。
一段時間后,我讓它作業了,但問題服務器給了我 ERR_EMPTY_RESPONSE。
- 服務器的 apache 在 windows server 2003 上是 2.2 ...
- PHP 版本是 5.2。
這是代碼:
<?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:: 我洗掉了最后一行的 @ 并進行了測驗。沒有任何事情按預期作業。
uj5u.com熱心網友回復:
所以...
這很丑陋,但它有效......
我剛改變
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);
正如我所說,它非常丑陋,但它有效,它使用戶下載檔案并且它不會卡住或類似的東西。
如果有人想做另一個真正的修復,我會測驗它,因為我不想改變位置。
再見。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/391219.html
