繁体   English   中英

使用 php 提供下载的大型 Zip 文件

[英]Large Zip file offered for download using php

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

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

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

相反,使用ob_end_clean丢弃和禁用 output 缓冲区,或者根本不使用 output 缓冲。

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

  1. output 缓冲。 您不希望 output 缓冲。 删除ob_start(); ob_clean(); 命令。 请注意,后者不会破坏 output 缓冲区
  2. 取消注释//set_time_limit(0); 以免遇到时间限制问题。
  3. 启用错误日志并从错误日志中了解脚本停止发送文件的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM