Handling POST Content-Length (PHP) Warning

I got problem when the file upload make the POST size exceed post_max_size setting.
I had disable the error report but the warning kept appearing.
Finally I found a solution.

In my case, I disabled all the PHP warning message using .htaccess.
To disable all errors from .htaccess use :
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0
From http://ca2.php.net/manual/en/ini.core.php#ini.post-max-size
If the size of post data is greater than post_max_size, 
the $_POST and $_FILES superglobals are empty. 
This can be tracked in various ways, e.g. by passing
the $_GET variable to the script processing the data,
i.e. , and then checking if $_GET['processed'] is 
set.


Here is the example to handle it in PHP:
if(empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ //catch file overload error...
  return $this->returnErrorMessage("File size exceed limit !!!");
}

Source : 
1. http://stackoverflow.com/questions/12872515/php-warning-demolishes-json-response
2.http://stackoverflow.com/questions/2133652/how-to-gracefully-handle-files-that-exceed-phps-post-max-size

0 comments:

 
Copyright © peyotest