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.
Answer
Solution:
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:
Of course your page should be designed not to submit empty POST pages with no input parameters.
Answer
Solution:
One thing what you can do is give a maximum size on the HTML form.
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.