I am building a custom app for a client (a photographer for commercial real estate) using typical PHP / MySql setup. This app will allow my client's clients to access images assigned to them, view them and download them.
I need to add the option to allow his clients to click "download all - print size quality" and "download all - web resolution". When images are uploaded, they will automatically be saved in those separate resolutions. To give you an idea, adding up the images a client would typically want to download, would equal up to 500MB. I think having all the images compressed to a zip would be the way to go.
How do you suggest I approach this, and if you know any source that may help me?
You can use PHP Zip
example can be found here : http://www.php.net/manual/en/zip.examples.php
OR
If you prefer dirty solution, you can use the linux built-in tar
function, and combine with exec
I assume you should have 3 different dimensions for each image, and your zip is only focus on select the images with correct dimension to add into archive.
However, the above is not an issue, you should convince your clients a better way to download these huge file, like consider using a ftp program, or some download tools instead of just via http hyperlink (chances of failure is way too high)
I would say zip would be the way to go. Using PHP to ZIP the selected files on the fly and then have the user download them automatically.
Probably having a user click checkboxes next to images in a form, the data sent to a processing page which spits out the ZIP file for the user.
this might help http://davidwalsh.name/create-zip-php
You should not generate a ZIP file on the fly for every download. This would be very inefficient.
When pictures are uploaded, create two new ZIP files from the images (one for each size). Add two columns to your table, on pointing to the smaller ZIP, and the other pointing to the larger. Just point your two links there.
Use ZipArchive, store it to a temporary file then output it:
$path = '/path/to/your/images';
// search for files matching *.png; *.gif; *.jpg
$files = glob($path.'/*.{png,gif,jpg}', GLOB_BRACE);
// create temporary filename
$tmp = tempnam(sys_get_temp_dir(), 'images');
// create zip
$zip = new ZipArchive;
$zip->open($tmp, ZIPARCHIVE::CREATE);
foreach ($files as $file) {
// may want to manipulate $file to remove the directory prefix
$zip->addFile($file);
}
$zip->close();
// output as an attachment
header('Content-Type: application/zip');
header('Content-Disposition: attachment;filename=foo.zip');
readfile($tmp);
Of course, if you really have 500MB of images, this will take a while. You're probably better off zipping your files in advance (a cron or on each upload).