php - How to avoid: Warning: POST Content-Length of 47820076 bytes exceeds the limit of 8388608 bytes in Unknown on line 0


I am posting an image file to the server and everything is fine. However, in cases when the user posts something bigger I get this warning. What could I do to avoid this warning?

I don't want solutions that would hide the warning nor increase the post size. I want something that would block the request from uploading the file to the server entirely and catch that warning.




This is what worked for me. It seems that when PHP sees a file that is too large, deletes all the POST data. So this code fragment worked for me:

if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_POST) < 1 ) {
    $_SESSION['error'] = 'File upload size exceeded';
    header('Location: index.php');

Of course your page should be designed not to submit empty POST pages with no input parameters.




One thing what you can do is give a maximum size on the HTML form.

<input type="hidden" name="MAX_FILE_SIZE" value="4194304" /> 

It's not bulletproof, but it has some impact. Why this is not so good is explained in this comment - it is only checked by PHP, so uploading will start and continue up until this limit is reached.

My recommendation is that you could use that together with a javascript solution, as described here. It only works if javascript is enabled, of course.

People are also looking for solutions to the problem: Php get image name in a link


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.