-1

We're working on a form to upload some files in Laravel 4, and the upload archives we have are rather large, up to around 500MB.

I want our system to throw an Exception when the POST size exceeds the size set in post_max_size, but instead of PHP throwing an exception, we are seeing a variable set by PHP called $php_errormsg and the application continues simply without any $_POST data.

Is there a way to configure PHP to automatically throw an Exception for this kind of error, or would I need to write some logic checking for example for the existence of $php_errormsg etc.

I think this is a rather weird way of dealing with this kind of error differently. Why deviate from standard PHP exceptions?

Another observation I made is that the $php_errormsg variable only exists when I check for it inside index.php, at the initial application entry point, but by the time Laravel 4 reaches the controller action, there's simply no concept of anything that went wrong, $php_errormsg is missing, and there's simply no Exception thrown and because $_POST got blanked out, we're getting validation errors for missing required fields rather than the actual:

POST Content-Length of x bytes exceeds the limit of x bytes

Debugging with XDebug in IntelliJ

josef.van.niekerk
  • 11,941
  • 20
  • 97
  • 157
  • did you try writing ini_set('display_errors', 'On'); error_reporting(E_ALL); at your scripts? – Riad Jan 10 '14 at 10:03
  • It is most definitely on, every other error that happens either shows up in the HTML output, or shows up in Laravel's error display page. It looks as if someone has suppressed some function call's errors with @ – josef.van.niekerk Jan 10 '14 at 10:05
  • Seems I'm not the only one having this issue: http://stackoverflow.com/questions/2133652/how-to-gracefully-handle-files-that-exceed-phps-post-max-size – josef.van.niekerk Jan 10 '14 at 10:14

1 Answers1

0

By adding the following code in my controller:

global $php_errormsg;
if (!is_null($php_errormsg)) {
    throw new Exception($php_errormsg);
}

I can display the error appropriately and deal with it by showing a proper error message to the user.

josef.van.niekerk
  • 11,941
  • 20
  • 97
  • 157