下载文件我的下载使用PHP停止在11MB

时间:2014-04-07 10:50:29

标签: php ziparchive

我正在使用zip存档生成一个zip文件并将其发送到浏览器供用户下载。

$archive_file_name = "/var/www/html/administrator/1396413991.zip";
header("Content-type: application/zip"); 
header("Content-Disposition: attachment; filename=test.zip"); 
header("Expires: on, 01 Jan 1970 00:00:00 GMT"); 
header("Pragma: no-cache"); 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
readfile("$archive_file_name");
exit;

我的下载在11Mb停止,我无法下载超过11mb的文件,我在做错了什么或不正确。

任何建议都将不胜感激。感谢。

2 个答案:

答案 0 :(得分:1)

我建议使用fpassthru代替它,它是专门针对这种情况制作的。

Note: 

Passthru didn't work for me for files greater than about 5Mb. Just adding "ob_end_clean()", all works fine now, including > 50Mb files.

$ToProtectedFile=$pathUnder.$filename
$handle = @fopen($ToProtectedFile, "rb");

@header("Cache-Control: no-cache, must-revalidate");
@header("Pragma: no-cache"); //keeps ie happy
@header("Content-Disposition: attachment; filename= ".$NomFichier);
@header("Content-type: application/octet-stream");
@header("Content-Length: ".$SizeOfFile);
@header('Content-Transfer-Encoding: binary');

ob_end_clean();//required here or large files will not work
@fpassthru($handle);//works fine now

答案 1 :(得分:0)

可能您可以尝试将您的php.ini设置更改为

memory_limit = 128M
post_max_size = 300M