Reputation: 27
I'm currently tinkering around with some code which allows me to upload files to my site. I am going to set an option in a configuration file which allows users to set the maximum upload limit. At the moment this has to be entered in kilobytes and I was wondering whether or not it'd be possible to have it entered in MB?
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
**&& ($_FILES["file"]["size"] < 2000000)** <---- Entered in Kilobytes, not MB.
&& in_array($extension, $allowedExts))
Upvotes: 0
Views: 84
Reputation: 5268
<?php
define('MB', 1024*1024);
echo 10*MB;
?>
That's another way to do it.
Also, there are no macros in C. So, it's not possible like in C,C++ to #define
these things.
Upvotes: 0
Reputation: 1412
It may be best to define a function to convert to MB to bytes, i.e.:
function MB($mb) {
return $mb*1024*1024;
}
Then you can make your comparison like:
($_FILES["file"]["size"] < MB(2000))
Upvotes: 0
Reputation: 2707
Just do this:
$b = 1000000;
$kb = $b / 1024;
$mb = $kb / 1024;
if($_FILES['size']['size'] < $mb * 2) {
// do something;
}
Upvotes: 1