How can I check for the size of the uploaded file?
php $_FILES["imageFile"]["size"]>30KB
??
Uploaded File Size
Moderator: General Moderators
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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.';
}
Last edited by The Bat on Tue Feb 13, 2007 2:43 pm, edited 1 time in total.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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
.. 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
personally for file size calculation i use:
this outputs the file size in mb with 2 digits after the comma like so
input:
12624855,04 Bytes
output
12,04 MB
Code: Select all
$file_size_mb = round($file_size_bytes / 1048576, 2);
echo "$file_size_mb MB";input:
12624855,04 Bytes
output
12,04 MB