In case a .zip download (with some photos inside) reaches a determined size, let's say 10MB, i want to print a javascript alert or any way of alert to the user, to inform him that the download has been capped because it reached the limit of 60MB.
I'm using MVC here, my controller know the .zip file size, but how do i send that alert after it reaches that limit and still give the file for user to download?
I'm outputting the file by setting headers Content-Type, Content-Length, Content-Disposition and filename:
// alert could be here
// 60000*1024 means 60MB
// if (filesize($file_zip) >= 60000*1024) alert('alert msg');
header('Content-Type: application/zip');
header('Content-Length: '.filesize($file_zip));
header('Content-Disposition: attachment; filename=testPhotos.zip');
readfile($file_zip);
unlink($file_zip);
I need to do this because for some reason, the request just stops after that .zip file reaches 63,7MB and the browser shows a blank screen. And no, the request doesn't timeout, because it's set to a high value. I don't know if thats a php or nginx config limitation.
Break this up into two ajax calls that you chain one after the other. On the first, request that the server zip the files up, return a success code along with a possible error message (file size too big, etc), and some sort of identifier for the zip file that was just created. If the zip wasn't too big, then request it directly with the identifier you just got. Otherwise, display your error message.