cantsay
cantsay

Reputation: 2046

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

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

If I try and upload (through a PHP script) a file which is more than 2MB, the browser doesn't stop when it gets to 2MB, it uploads the entire thing, and then my PHP script says it's too large.

My question is, why does the browser not stop at 2MB and reject the file? Since the file won't be stored if it's over the limit, where does this data being uploaded actually go?

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

Upvotes: 3

Views: 93

Answers (1)

Wrikken
Wrikken

Reputation: 70500

PHP only gets the request after it's completed. If you want to abort earlier, there are methods in your webserver, like Apache's LimitRequestBody or nginx's client_max_body_size. Those fail quite ugly though, to make it more user friendly another option is to use chunked uploads, there are several options mentioned in this question

Upvotes: 1

Related Questions