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. Only downloading 45MB to 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. Therefore, the output of readfile
is buffered in memory, which is limited by php's memory_limit
directive.
Instead, use ob_end_clean
to discard and disable the output buffer, or don't use output buffering at all.
This might not solve all your problems, however I see the following:
- output buffering. You don't want output buffering. Remove the
ob_start();
andob_clean();
commands. Note that the latter will not destroy the output buffer. - uncomment
//set_time_limit(0);
to not run into time limit problems. - enable error logging and learn from the error log why the script stops sending the file.
精彩评论