Entry
How can I limit the filesize of a file upload?
Sep 8th, 2004 14:22
Olaf Lederer, http://www.php.net/manual/en/features.file-upload.php
Just put a hidden field inside your upload form and call this field
"MAX_FILE_SIZE". Inside the value there is room for the size in bytes
ex. 100*1024 = 100KB. After this a lot of people get in trouble.
First, you have to know what is the max. filesize in the php
configuration. That will mean files above this value (default 2mb) will
not be uploaded (even you say this in your hidden formfield). You can
handle error's with the error array of your uploaded file, take a look
in the manual!
Second, there is another limit inside the php configuration: the maximum
post size. All files above this value are not processed by the server.
Conclusion: Before your start limiting the filesize for uploading files
you have to know these values! Your hidden form field value is the last
check but will work for you! And please remember: you can only check
uploaded files on the server! Success.