Search code examples
phpexceptionlaravellaravel-3

Laravel 3 - POST Content-Length Exception


Running Laravel 3.

I am trying to upload files with the laravel framework. If the file is larger than the php setting for upload_max_filesize it throws the exception below.

I have tried this in my controller and routes with no success (the if statement runs - it sets a session - but the exception is still thrown showing the error page)

if ($_SERVER['CONTENT_LENGTH'] > 8380000) {
    //do stuff here because its too big
    // set a session and exit()
}

How can I prevent this exception from being thrown without upping the php memory limits?

Error:

Unhandled Exception

Message:

POST Content-Length of 9306598 bytes exceeds the limit of 8388608 bytes
Location:

Unknown on line 0

As a side note, this question has been asked atleast twice in the laravel forum with no good answer given except for 'increase your php memory limits'.

EDIT: the problem seems to be that laravel is loading all the _POST inputs before I can even check them in the route or controllers. Seems like a bug to me.


Solution

  • This looks like PHP's max post size, which defaults to 8M on many systems (around 8388608 bytes). There is nothing you can do in Laravel to get around this as it is handled/managed/configured at the PHP level. Read Increasing the maximum post size to see how to change this.