providing multiple file download for site user
Posted: Wed Dec 29, 2010 5:02 am
I am working on a photo website and would like to provide users with the possibilety to download multiple images out of a shopping basket like configuration.
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.
Trying to implement a loop going through a list of files stops after the first file downloaded.
I would be very happy if anybody knows a working solution to it. Thanks
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);
}
}