What does PHP do when a user uploads a file over limit?

My PHP is configured with a 2MB limit for file uploads.

If I try to download (via a PHP script) a file larger than 2MB, the browser doesn't stop when it reaches 2MB, it downloads the whole thing, and then my PHP script says it's too big.

My question is, why doesn't the browser stop at 2MB and reject the file? Since the file will not be saved if it exceeds the limit, where is this data actually loaded?

My VPS is configured with 512MB of RAM and 7GB of storage. Does this mean that someone might upload a file larger than 512MB or 7GB and it will kill the server because it runs out of memory / space?

+3


source to share


1 answer


PHP only receives the request after it completes. If you want to abort early, your web server has methods like Apache LimitRequestBody

or nginx client_max_body_size

. However, they are not entirely ugly to make it more user-friendly. Another option is to use chunked uploads, there are several options mentioned in this question



+1


source







All Articles