I am quite surprise to find the above-mentioned error in my error log because I thought I have already done the necessary work to catch the error in my PHP script:
if ($_FILES['image']['error'] == 0)
{
// go ahead to process the image file
}
else
{
// determine the error
switch($_FILES['image']['error'])
{
case "1":
$msg = "Uploaded file exceeds the upload_max_filesize directive in php.ini.";
break;
....
}
}
In my PHP.ini script, the relevant settings are:
memory_limit = 128M
post_max_size = 3M
upload_max_filesize = 500K
I understand that the 3M is equivalent to 3145728 bytes and that this is what that is triggering the error. If the file size is above 500k but less than 3M, the PHP script would be able to run as per normal, issuing the error message in $msg
as per case 1
.
How do I catch this error instead of letting the script terminate abruptly with a PHP warning when post size exceeds post_max_size
but still well within the memory limit? I have looked at similar questions here, here and here, but couldn't find an answer.