图像大小检查不工作的PHP

时间:2014-01-12 22:53:07

标签: php

我正在尝试检查图像大小是否不大于3mb但是如果我上传2 - 3mb图像,我会收到一个错误,表示图像大小超过3mb。有什么想法吗?

$size = $_FILES['image']['size'];
$one_MB = 1024*1024; //1MB
if($size > ($one_MB*3))
{
echo"File exceeds 3MB";
}
else{
if (move_uploaded_file($_FILES['image']['tmp_name'], $new_location)){
 //do something
} 
else{
echo "Image is too big, try uploading below 3MB"; //this is the error it shows 
even if the image is not greater than 3mb and not invalid image. If I reduce the image
size to 1.5mb it goes through.
}
}

0 个答案:

没有答案