hugopereira84
4/17/2015 - 3:15 PM

How to gracefully handle files that exceed PHP's `post_max_size`

How to gracefully handle files that exceed PHP's post_max_size

if(empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ //catch file overload error...
  $postMax = ini_get('post_max_size'); //grab the size limits...
  echo "<p style=\"color: #F00;\">\nPlease note files larger than {$postMax} will result in this error!<br>Please be advised this is not a limitation in the CMS, This is a limitation of the hosting server.<br>For various reasons they limit the max size of uploaded files, if you have access to the php ini file you can fix this by changing the post_max_size setting.<br> If you can't then please ask your host to increase the size limits, or use the FTP uploaded form</p>"; // echo out error and solutions...
  //addForm(); //bounce back to the just filled out form.
}else{
  // continue on with processing of the page...
}
There is a way to catch / handle files exceeding max post size, this is my preferred on, as it tells the end user what has happened and who is at fault ;)