PHP Warning: POST Content-Length of n bytes exceeds the limit of 3145728 bytes in Unknown on line 0
===

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][1], [here][2] and [here][3], but couldn't find an answer.


  [1]: http://stackoverflow.com/questions/11719495/php-warning-post-content-length-of-8978294-bytes-exceeds-the-limit-of-8388608-b
  [2]: http://stackoverflow.com/questions/6315358/php-warning-post-content-length-of-113-bytes-exceeds-the-limit-of-1988100096-b
  [3]: http://stackoverflow.com/questions/6279897/php-post-content-length-of-11933650-bytes-exceeds-the-limit-of-8388608-bytes