I have a project where the user can add multiple files to a cart and then zip them into a single file and download all of them at once.
It seems though that as soon as the cart gets bigger then 10mb it cannot create the zip file. I thought this might be because of upload_max_filesize, but that is set to 200m and same for post_max_size.
What would be limiting this?
Here is my code. It creates a random file name, then checks the cart loop and adds each file.
// create object
$zip = new ZipArchive();
$filename = "loggedin/user_files/ABX-DOWNLOAD-".rand(1, 1000000).".zip";
while (file_exists($filename)):
$filename = "loggedin/user_files/ABX-DOWNLOAD-".rand(1, 1000000).".zip";
endwhile;
// open archive
if ($zip->open('../'.$filename, ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
// add files
//echo $all_audio;
foreach($audio_ids as $audio_id){
if($audio_id != ""){
$audio = Audio::find_by_id($audio_id);
$selected_category = Categories::find_by_id($audio->category_id);
$selected_sub_category = Sub_Categories::find_by_id($audio->sub_category_id);
$selected_sub_sub_category = Sub_Sub_Categories::find_by_id($audio->sub_sub_category_id);
$f = "uploads/mp3/".$selected_category->category_name."/".$selected_sub_category->sub_category_name."/".$selected_sub_sub_category->sub_sub_category_name."/".$audio->media_path;
$zip->addFile($f) or die ("ERROR: Could not add file: $f");
}
}
// close and save archive
$zip->close() or die("ERROR: COULD NOT CLOSE");
}
Well, narrowed it down. A pathname was corrupted and was making the zip error out because the file did not exist. Looks like I need some better error checking.