I would like to use $_FILES['name']['size']
to see if the size of the file being uploaded is bigger than 1MB. How can I do this? What do I use for the size in my if statement?
Like this?:
if ( $_FILES['name']['size'] >= 1Mb) {
// do this;
}
The size is represented in bytes. 1 MB is 1024 * 1024 bytes.
if ( $_FILES['name']['size'] >= 1024 * 1024) {
// do this;
}
No, since that is a string and the size is an integer in terms of bytes.
Given that 1Mb is 1000Kb is 1,000,000b, this will work:
if ( $_FILES['name']['size'] >= 1 * 1000 * 1000)
I'm assuming though that you mean MB, since files are expressed in bytes (B) instead of bits (b). In that case, use 1024 instead of 1000 (1MB = 1024KB. 1KB = 1024B).
From the manual:
$_FILES['userfile']['size']
The size, in bytes, of the uploaded file.
1MB is (1024*1024) bytes (or 1048576B), so:
if ($_FILES['name']['size'] >= 1024*1024) {
// do this;
}
Please use the documentation.