2014-10-18 67 views
0

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

代码:

$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); 

我想即使有锚标记和相同happend。我还将扩展名从.msi更改为.txt,并且字节也从下载的文件中删除。

我只是无法弄清楚

+1

你在使用到测量前后的字节数?这可能只是不同的工具使用不同的兆字节(1000 * 1000与1024 * 1024)的定义 – IMSoP 2014-10-18 10:53:13

+0

我正在检查这两个文件的属性。一个在服务器上,一个在下载。而且我甚至在记事本++中打开了两个文件,原来的文件比下载的文件多。 – Frog 2014-10-19 08:47:52

+0

代码在我的本地服务器上正常工作。我认为问题是托管服务器。也许在我无法访问的ini文件中有一个指令。 – Frog 2014-10-19 08:49:54

回答

0

试试这个

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