This is an easy way to solve this problem:
Just run "checkPostSizeExceeded" when you run your code
function checkPostSizeExceeded() { if (isset($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] == 'POST' and isset($_SERVER['CONTENT_LENGTH']) and empty($_POST)//if is a post request and $_POST variable is empty(a symptom of "post max size error") ) { $max = get_ini_bytes('post_max_size');//get the limit of post size $send = $_SERVER['CONTENT_LENGTH'];//get the sent post size if($max < $_SERVER['CONTENT_LENGTH'])//compare throw new Exception( 'Max size exceeded! Were sent ' . number_format($send/(1024*1024), 2) . 'MB, but ' . number_format($max/(1024*1024), 2) . 'MB is the application limit.' ); } }
Remember a copy of this helper function:
function get_ini_bytes($attr){ $attr_value = trim(ini_get($attr)); if ($attr_value != '') { $type_byte = strtolower( $attr_value{strlen($attr_value) - 1} ); } else return $attr_value; switch ($type_byte) { case 'g': $attr_value *= 1024*1024*1024; break; case 'm': $attr_value *= 1024*1024; break; case 'k': $attr_value *= 1024; break; } return $attr_value; }
Doglas Nov 29 '16 at 18:28 2016-11-29 18:28
source share