Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dave_ac's avatar

File upload MethodNotAllowedHttpException

Hi Folks any help appreciated.

Summary: Uploading large files redirects with an error page with

MethodNotAllowedHttpException in RouteCollection.php line 218:

For files less than 2mb everything is fine and can be processed For files less than 8mb the form submits in the normal fashion and behaves as expected. For files equal to and greater than 8mb I get the MethodNotAllowedHttpException, the url is no longer the expected one. It should be co.uk/item/1/edit but i get co.uk/item/1 the Request Method: POST

Form: `

<input type="hidden" name="MAX_FILE_SIZE" value="2097152">
`

The route Route::resource('/item', 'ItemController');

The Controller is a resource. I get this error if the controller method is empty or performing tasks

public function update(Request $request, $id) { return redirect()->action('ItemController@edit', ['id' => $id]); }

Any thoughts?

0 likes
10 replies
dave_ac's avatar

Morning. @jlrdw and @Snapey Thanks, but I am wanting to retain the max file sizes.

If a user tries to upload too large a file it should not be saved and an $error returned. At the moment its just the grey error page and as @Snapey says the verb is getting lost --- at what point and how to prevent it....

I can see this morning not being very productive

Snapey's avatar

Its because the allowed POST size is smaller than the max upload. The input gets truncated and that breaks the routing.

Keep your max upload size but then make the post size a little larger to allow for the rest of the form.

Remember also that you can apply size checks as a validation rule and catch too large files gracefully in your code.

1 like
dave_ac's avatar

This is frustrating, I know when it is fixed there will be a facepalm moment

Here are the settings, still no joy

Max_file_uploads: 20

Post_max_size: 4M

Upload_max_filesize: 3M

Memory_limit: 128M

<input type="hidden" name="MAX_FILE_SIZE" value="3145728">

Try to upload a 6Mb file ……. Routeing snaps !@£$ !@!$%&£

I don’t want to rely on client side js validation if, when it gets server side it all goes tits up.

Cheers,

Snapey's avatar

have you validated these by doing a phpinfo from your script? I ask because all these settings should have a lower case letter at the start

dave_ac's avatar

@Snapey, Yes in coped text from phpinfo and double checked that i was editing the correct file and restarted the server.

I am at the point of doing a fresh install of Laravel and recreate the form and process to see if there is an issue with something i have done elsewhere ....

Thanks again for the reply

dave_ac's avatar
dave_ac
OP
Best Answer
Level 5

Okay this is what i have so far.

In app/Http/Kernel I have found and added the following to the global $middleware

'\Illuminate\Foundation\Http\Middleware\VerifyPostSize::class,'

Great news i know get a "PostTooLargeException" error and still loose the put/patch header

I've not done anything with custom exceptions and the Exception Handler so I need to read up and try to figure out how to catch and redirect back to the /edit or /create pages

1 like
hanspeter's avatar

Hi, I just had the same problem and my experience was, that the post_max_size had to be significantly larger than upload_max_filesize.

When I had:

upload_max_filesize = 20M
post_max_size = 25M

I still experienced the MethodNotAllowedHttpException. However with

upload_max_filesize = 20M
post_max_size = 50M

it went away (and gave place to the proper FileException)

1 like
Snapey's avatar

@hanspeter the uploaded image may be base64 encoded causing significant overhead

1 like

Please or to participate in this conversation.