Since I am dealing with large original image files any attempt to create a zipped archive using zlib fales soon as there are more than 4 to 5 files in the cart due to server load limitations etc.
Using simple http headers works fine for providing a single file download.
Code: Select all
Header("Content-type: application/octet-stream");
Header ("Content-disposition: attachment; filename=archive.zip"); //filename could be any sample.txt or sample.jpg
echo $zip->file(); //in this case the link to the file pulled out of a compression classCode: Select all
if(ini_get('zlib.output_compression'))ini_set('zlib.output_compression', 'Off');
switch($fileExtension)
{
case "gif" : $ctype = "image/gif"; break;
case "png" : $ctype = "image/png"; break;
case "jpg" : $ctype = "image/jpg"; break;
case "jpeg" : $ctype = "image/jpeg"; break;
default : $ctype = "application/force-download";
session_cache_limiter("");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=".basename($sourceFile).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($sourceFile));
$file = fopen($sourceFile, "rb");
if($file)
{
while(!feof($file))
{
print(fread($file, 1024*8));
flush();
if(connection_status() != 0)
{
@fclose($file);
die();
}
}
@fclose($file);
}
}