Forum Moderators: coopster

Message Too Old, No Replies

Verifying file size prior to uploading

         

fashezee

7:55 pm on Sep 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We have a limit set for the file size our clients can upload. We allow them to upload up to 5 images with a total size limited of 5mb.

Although its clearly stated what the limits are; users are still attempting to upload more than 5MB. I have not been able to find a script that allows me to verify the file size instantly and provide the user the appropriate error message without having to download the entire images; anyone have experience regarding this?

mcibor

9:11 pm on Sep 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I found in some upload script, that you can use properties of $_FILES variable:

$max_size = 1024*1024; //= 1MB
if($_FILES['userfile']['size'] > $max_size) die("Too large file. It must be maximum 1MB");

Hope this helps
Michal Cibor

dcrombie

1:54 pm on Sep 6, 2005 (gmt 0)



I don't think you can verify the file sizes _before_ they are uploaded. If someone knows otherwise I'd be very interested ;)

henry0

3:40 pm on Sep 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I will set a temp dir
let the user upload
check from temp dir
if ok move to production
if not = error message as per mcibor suggestion
then del from temp dir.