【发布时间】:2014-01-31 16:05:21
【问题描述】:
我曾问过这个问题,发现 PHP 配置将我的上传限制为 2MB,因此我将其固定为 3MB。但是,我现在有另一个问题:我也在检查图像尺寸,如果图像看起来超过 3MB,它就会失败,抛出以下错误。那么我怎样才能停止错误并自己检查大小而不是 PHP 配置呢?
警告:getimagesize():文件名不能为空
代码如下:
$size = $_FILES['image']['size'];
list($width, $height) = getimagesize($_FILES['image']['tmp_name']);
$minh = 400;
$minw = 600;
$one_MB = 1024*1024; //1MB
if($size > ($one_MB*3))// this is not checking the size at all, the last echo is what I get if I try to upload over 3mb.
{
echo"File exceeds 3MB";
}
elseif ($width < $minw ) {
echo "Image width shouldn't be less than 600px";
}
elseif ($height < $minh){
echo "Image height shouldn't be less than 400px";
}
else{
if (move_uploaded_file($_FILES['image']['tmp_name'], $new_location)){
//do something
}
else{
echo "Image is too big, try uploading below 3MB";
}
}
【问题讨论】:
标签: php