提供使用 php 下载的大型 Zip 文件
我使用的下载代码如下..
ob_start();
ini_set('memory_limit','1200M');
set_time_limit(900);
// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
apache_setenv('no-gzip', '1');
$filename = "test.zip";
$filepath = "http://demo.com/";
// http headers for zip downloads
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filepath.$filename));
//set_time_limit(0);
ob_clean();
flush();
readfile($filepath.$filename);
exit;
我的文件大小是 100MB zip 文件。仅下载 45MB 至 50MB。我不知道问题出在哪里。请帮我...
I used code for downloading as follows..
ob_start();
ini_set('memory_limit','1200M');
set_time_limit(900);
// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
apache_setenv('no-gzip', '1');
$filename = "test.zip";
$filepath = "http://demo.com/";
// http headers for zip downloads
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filepath.$filename));
//set_time_limit(0);
ob_clean();
flush();
readfile($filepath.$filename);
exit;
my file size is 100MB zip file. Only downloading 45MB to 50MB. I dont no where is the problem. please help me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ob_clean 丢弃输出缓冲区的当前内容,但不禁用它。因此,
readfile
的输出被缓存在内存中,这受到php的memory_limit
指令。相反,使用
ob_end_clean
丢弃并禁用输出缓冲区,或者根本不使用输出缓冲。ob_clean
discards the current content of the output buffer, but does not disable it. Therefore, the output ofreadfile
is buffered in memory, which is limited by php'smemory_limit
directive.Instead, use
ob_end_clean
to discard and disable the output buffer, or don't use output buffering at all.这可能无法解决您的所有问题,但是我看到以下内容:
ob_start();
和ob_clean();
命令。请注意,后者不会破坏输出缓冲区。//set_time_limit(0);
以免遇到时间限制问题。This might not solve all your problems, however I see the following:
ob_start();
andob_clean();
commands. Note that the latter will not destroy the output buffer.//set_time_limit(0);
to not run into time limit problems.