【发布时间】:2018-12-23 17:02:28
【问题描述】:
设置文件大小标题后压缩损坏
我有这个代码来限制 php 的下载速度:
function readfile_chunked($filename, $retbytes = TRUE) {
$download_rate = 85; global $filename ;
// send headers
header('Cache-control: private');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($filename));
header('Content-Disposition: filename=file.zip');
// flush content
flush();
// open file stream
$file = fopen($filename, "r");
while(!feof($file)) {
// send the current file part to the browser
print fread($file, round($download_rate * 1024));
// flush the content to the browser
flush();
// sleep one second
usleep(200);
}
}
当我像这样设置内容长度的标题时:
header('Content-Length: '.filesize($filename));
并打开下载的文件向我显示文件已损坏的警报。不仅仅是我在 jpg 文件上尝试的 zip 文件,而且它是相同的。
但是当我删除文件大小标题时,文件或图像打开时没有任何错误
【问题讨论】:
标签: php download http-headers zip zipfile