I'm trying to create a method to Dynamically zip assets to allow users to download all high res product folders in one zip file. I'm having trouble implementing the code. The zip file method works on its own outside of SS.
Right now I've just specified the paths to a few files as a test senerio, I keep getting a 500 error
function CreateZip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
//close the zip -- done!
$zip->close();
//check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}
function ZipLink() {
//$files_to_zip = GetAllImagePaths();
$files_to_zip = array (
'assets/Products/Tower/Tower.jpg',
'assets/Products/Tower/Tower-Side.jpg',
'assets/Products/Classic/T0001-detail.jpg',
'assets/Products/Classic/T0001-box-2.jpg',
'assets/Products/Classic/T0002-detail.jpg',
'assets/Products/Classic/T0002-box-2.jpg',
'assets/Products/Classic/T0003-detail.jpg',
'assets/Products/Classic/T0003-box-2.jpg');
if ($files_to_zip) {
$result = CreateZip($files_to_zip, 'assets/my-archive.zip');
if ($result) {
return "success";
} else {
return "fail";
}
} else {
return false;
}
}
Thanks for any Help