PHP文件下载字节丢失


PHP file downloads bytes missing

我正在尝试下载一个实际大小为5.77MB的.msi文件。当我执行脚本时,下载的文件将丢失一些字节,并将变为4.88MB。

代码:

$file = 'apps/file.msi';
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 5');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);

我甚至试着使用锚标签,结果也发生了同样的事情。我还将扩展名从.msi更改为.txt,并且还从下载的文件中删除了字节。

我就是搞不懂

试试这个

$file = 'apps/file.msi';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename='"" . basename($file) . "'""); 
readfile($file); 

也许您的服务器配置为gzip传输的内容

http://en.wikipedia.org/wiki/HTTP_compression