|
Posted by Andy Hassall on 08/22/06 23:55
On 22 Aug 2006 14:59:35 -0700, "jeremyz" <jeremy.zorn@gmail.com> wrote:
>I am not a developer, but I work with several and am posting this for
>them. We are trying to determine whether it is possible to check the
>size of a file before a user uploads it.
>
>Everything I've read suggests that this is impossible (or at least very
>difficult) in PHP, and this makes sense for a server-side language.
>What gives me pause, however, is the fact that when a user tries to
>upload a file larger than the max file size we allow, an error appears
>in our error log immediately -- yet the upload continues.
>
>So somehow PHP must be recognizing that the file is too big well before
>it's been uploaded. The question is how -- and how do we make the leap
>from that recognition to an immediate halt of the upload?
The browser may send a Content-length header with the file upload. PHP can
read this immediately, since it's right at the start of the request, and so can
produce an error in the log if it's too big.
However, there's no way for PHP to send a response to the browser yet, because
the content of the file is part of the HTTP request. Its choices are to either
unceremoniously dump the connection without a response (which it doesn't do,
for obvious reasons, although the HTTP protocol does allow this), or wait until
the request has finished so it can send a response back with an error message.
AFAIK this is a limitation of the HTTP protocol and so cannot be worked
around.
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
[Back to original message]
|