title: PHP Warning: POST Content-Length of n bytes exceeds the limit of 3145728 bytes in Unknown on line 0
body: <p>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:</p>
  
  <pre><code>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;
    ....
   }
  }
  </code></pre>
  
  <p>In my PHP.ini script, the relevant settings are: </p>
  
  <pre><code>memory_limit = 128M
  post_max_size = 3M
  upload_max_filesize = 500K
  </code></pre>
  
  <p>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 <code>$msg</code> as per <code>case 1</code>.</p>
  
  <p>How do I catch this error instead of letting the script terminate abruptly with a PHP warning when post size exceeds <code>post_max_size</code> but still well within the memory limit? I have looked at similar questions <a href="https://stackoverflow.com/questions/11719495/php-warning-post-content-length-of-8978294-bytes-exceeds-the-limit-of-8388608-b">here</a>, <a href="https://stackoverflow.com/questions/6315358/php-warning-post-content-length-of-113-bytes-exceeds-the-limit-of-1988100096-b">here</a> and <a href="https://stackoverflow.com/questions/6279897/php-post-content-length-of-11933650-bytes-exceeds-the-limit-of-8388608-bytes">here</a>, but couldn't find an answer.</p>