【问题标题】:Large Zip file offered for download using php提供使用 php 下载的大 Zip 文件
【发布时间】:2011-07-18 13:58:37
【问题描述】:

我使用的下载代码如下..

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。我不知道问题出在哪里。请帮帮我...

【问题讨论】:

  • 嗨,你能解决这个问题吗?

标签: php download zip


【解决方案1】:

ob_clean 丢弃输出缓冲区的当前内容,但不禁用它。所以readfile的输出是缓存在内存中的,受php的memory_limit指令限制。

改为使用ob_end_clean 丢弃和禁用输出缓冲区,或者根本不使用输出缓冲区。

【讨论】:

    【解决方案2】:

    这可能无法解决您的所有问题,但我看到以下内容:

    1. 输出缓冲。你不想要输出缓冲。删除 ob_start();ob_clean(); 命令。注意后者will not destroy the output buffer
    2. 取消注释//set_time_limit(0);,以免遇到时间限制问题。
    3. enable error logging 并从错误日志中了解脚本停止发送文件的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多