Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
提供使用php下载的大型Zip文件_Php_Download_Zip - Fatal编程技术网

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

提供使用php下载的大型Zip文件,php,download,zip,Php,Download,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');

我使用的代码下载如下

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
丢弃输出缓冲区的当前内容,但不禁用它。因此,
readfile
的输出缓冲在内存中,这受到php指令的限制


相反,使用可放弃和禁用输出缓冲区,或者根本不使用输出缓冲。

这可能无法解决所有问题,但我看到以下情况:

  • 输出缓冲。您不需要输出缓冲。移除
    ob_start()
    ob_clean()命令。注意后者
  • 取消注释
    //设置时间限制(0)以避免遇到时间限制问题
  • 并从错误日志中了解脚本停止发送文件的原因
    嗨,你能解决这个问题吗?