anand
anand

Reputation: 11

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...

Upvotes: 1

Views: 1717

Answers (2)

hakre
hakre

Reputation: 198217

This might not solve all your problems, however I see the following:

  1. output buffering. You don't want output buffering. Remove the ob_start(); and ob_clean(); commands. Note that the latter will not destroy the output buffer.
  2. uncomment //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.

Upvotes: 0

phihag
phihag

Reputation: 288298

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.

Upvotes: 2

Related Questions