So for some reason this just doesn’t make sense to me.
What Im trying to do is display 1 of 2 things:
- If the filesize of just 1 image in the folder is too big, display the error message I have above.
- If all of the filesizes are ok, display a bit of HTML code
Also, is my threshold correct if I want the limit to be 5MB?
<?php
$threshold = 5368709120;
$path = 'dir/'.$username;
foreach (glob($path."/{*.gif,*.jpg,*.jpeg,*.png}",GLOB_BRACE|GLOB_NOSORT) as $filename)
{
$size = filesize($filename);
if ($size > $threshold) {
exit('One or more of your photos are larger than 5MB. Resize your photos and try again.');
}
}
?>
No, your file limit is actually 5 gigabytes:
For user friendliness, you should tell the user WHICH file is too large, as well as check ALL the files before exiting. Let’s say the user didn’t know there was a 5 meg limit, and uploaded 50 files. 49 are too large. You’re just telling the user there’s a problem, not what caused the problem. Now they have to re-upload a file, then do it again. now there’s 48 files too big, and around they go.
Something like this would be more appropriate