Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php upload and bandwidth/traffic question

I have set upload limit to 3M in php.ini. If someone uploads a file that is 50 mb, then does the upload stop when it hits 3Mb or does it continue until the upload is complete, then reads the filesize and deletes the file?

like image 749
BlackBrother Avatar asked Jul 01 '11 09:07

BlackBrother


1 Answers

If you're using Apache as your web server, then PHP doesn't get a chance to start until the request completes. Thus, the upload limit only comes into action after the whole upload finishes. Apache first receives the entire request, and only then does it invoke the appropriate handler (in this case, PHP). Since there is no server-side mechanism to abort a HTTP request in progress and return a response, you'll need to wait until the whole request is complete.

So, to answer your question: NO, the upload will go through in full; PHP's internal logic will check the uploaded file size, see that it's larger than the limit, and then fail immediately with an error. Your PHP script will not get a chance to run, so don't rely on runtime checks - they won't be executed at all.

like image 182
Piskvor left the building Avatar answered Sep 28 '22 20:09

Piskvor left the building