简体   繁体   English

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

[英]Large Zip file offered for download using php

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.我的文件大小是 100MB zip 文件。 Only downloading 45MB to 50MB.仅下载 45MB 到 50MB。 I dont no where is the problem.我不知道问题出在哪里。 please help me...请帮我...

ob_clean discards the current content of the output buffer, but does not disable it. ob_clean丢弃 output 缓冲区的当前内容,但不会禁用它。 Therefore, the output of readfile is buffered in memory, which is limited by php's memory_limit directive.所以readfile的output缓冲在memory中,受php的memory_limit指令限制。

Instead, use ob_end_clean to discard and disable the output buffer, or don't use output buffering at all.相反,使用ob_end_clean丢弃和禁用 output 缓冲区,或者根本不使用 output 缓冲。

This might not solve all your problems, however I see the following:这可能无法解决您的所有问题,但是我看到以下内容:

  1. output buffering. output 缓冲。 You don't want output buffering.您不希望 output 缓冲。 Remove the ob_start();删除ob_start(); and ob_clean();ob_clean(); commands.命令。 Note that the latter will not destroy the output buffer .请注意,后者不会破坏 output 缓冲区
  2. uncomment //set_time_limit(0);取消注释//set_time_limit(0); to not run into time limit problems.以免遇到时间限制问题。
  3. enable error logging and learn from the error log why the script stops sending the file.启用错误日志并从错误日志中了解脚本停止发送文件的原因。

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

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