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

sajadsholi's avatar

PostTooLargeException add warning to response

I handle the PostTooLargeException in handler file in render function like this

            if ($e instanceof PostTooLargeException) {
                return Json::response(
                    status: 413,
                    message: __(key: 'messages.postIsTooLarge', locale: request()->header('Accept-language', 'fa')),
                );
            }

my project is full in API and I don't have any blade so I always return json when I upload a big file laravel add a warning to my json response like this

<br />
<b>Warning</b>:  POST Content-Length of 2959075 bytes exceeds the limit of 1048576 bytes in <b>Unknown</b> on line <b>0</b><br />
{"status":413,"success":false,"message":"The size of data is too large","errors":[],"data":[]}

why and where the laravel add this warning and how can I remove them?

the Json::response() is my custom and a small facade and this warning is not related to the Json facade

0 likes
8 replies
gych's avatar

This is not a default laravel warning, its a server warning stating that the upload is too big and thehrefor can't be uploaded. Either update your server configuration to handle uploads of bigger size or upload your file in chunks depending on what the contents of the file are.

shariff's avatar

@sajadsholi As @gych told you need to do modification in the server. Not in the application. You need increase the upload_max_filesize or post_max_size values in the settings.

If you don't have server access you can increase the upload size during run time using ini_set('upload_max_filesize', '10M');.

gych's avatar

@sajadsholi Well if the upload max filesize is set to 10M the warning will still be triggered when uploading an 11mb file. To upload bigger files than 10MB the value of upload max filesize needs to be higher than 10M

What type of files are uploaded?

sajadsholi's avatar

@gych I mean I want to handle the error not prevent the happing of error

gych's avatar

@sajadsholi Than you should validate the file size before posting it to the server. You can do that with javascript.

Please or to participate in this conversation.