似乎我成功地创建了一个即时 zip 存档(filesize 和 file_exists 都返回预期值)但是当我尝试实际下载它时,我收到一个空的 ZIP 文件。奇怪的是,readfile 和 fread 都会出现这个错误。这是我的代码
$filename = $zip;
$handle = fopen($filename, 'r');
if ($handle === false)
{
die('Could not read file "' . $filename . '"');
}
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="fsdownload.zip"');
header('Cache-Control: private');
while (!feof($handle))
{
echo fread($handle, 8192);
}
fclose($handle);
这适用于 < 10 MB 的 zip 文件。有什么想法可能是什么问题?