Page 1 of 1

Uploaded File Size

Posted: Mon Feb 12, 2007 8:13 pm
by AliasBDI
How can I check for the size of the uploaded file?

php $_FILES["imageFile"]["size"]>30KB

??

Posted: Mon Feb 12, 2007 9:32 pm
by Kieran Huggins
do a print_r($_FILES) to inspect the format of the array and it's data

Posted: Tue Feb 13, 2007 12:33 am
by The Bat
If you're talking about size validation before the actual uploading, you could use an if statement:

Code: Select all

if ($_FILES['imagefile']['size'] >= 30720) { // 30KB = 30720B
   // Proceed with uploading...
} else {
   echo 'The file is too large. Please try again.';
}

Posted: Tue Feb 13, 2007 8:23 am
by feyd
30KB is 30720 bytes. ;)

.. and PHP will do the size check (if possible) for you using two directives (upload_max_filesize and post_max_size) and possibly one form submission (MAX_FILE_SIZE). Details can be found here: http://php.net/features.file-upload

Posted: Tue Feb 13, 2007 8:37 am
by ryuuka
personally for file size calculation i use:

Code: Select all

$file_size_mb = round($file_size_bytes / 1048576, 2);

echo "$file_size_mb MB";
this outputs the file size in mb with 2 digits after the comma like so
input:
12624855,04 Bytes

output
12,04 MB