Php 图像上载表单维度验证

Php 图像上载表单维度验证,php,Php,sir是否可以检查上传的图像尺寸是否与此尺寸匹配250、468x60、320x50、216x36、168x28、300x250、300x50 如果不匹配,错误消息将如下所示 图像大小无效,可用大小为300x250、468x60、320x50、216x36、168x28、300x250、300x50检查此代码:- $file = $_FILES["files"]['tmp_name']; // uploaded files list($width, $height) = getimagesize(

sir是否可以检查上传的图像尺寸是否与此尺寸匹配250、468x60、320x50、216x36、168x28、300x250、300x50

如果不匹配,错误消息将如下所示

图像大小无效,可用大小为300x250、468x60、320x50、216x36、168x28、300x250、300x50检查此代码:-

$file = $_FILES["files"]['tmp_name']; // uploaded files
list($width, $height) = getimagesize($file);
$string = $width.'x'.$height;
$predefined_sizes = array('300x250', '468x60', '320x50', '216x36', '168x28', '300x250', '300x50'); // custom image size array
if(!in_array($string,$predefined_sizes)) {
    echo "Image Size is not valid, available sizes are 300x250, 468x60, 320x50, 216x36, 168x28, 300x250, 300x50";
    // Or you can also do to avoid repetion of sizes.
    //echo "Image Size is not valid, available sizes are ".implode(', ',$predefined_sizes);
    exit;
}else{
    echo 'Valid image'; 
}

可能是一个尺寸的重复,先生,我想设置精确的maltiple尺寸匹配您可以根据需要调整答案,基本上您只需要GD库附带的
getimagesize
,然后您可以有多个ifs或
|
好的,先生,请回答。让我查一下
$file=$uploaddir . basename($_FILES['file']['name']);

if (move_uploaded_file($_FILES['file']['tmp_name'], $file)) {

    $size = getimagesize($files);

    $maxWidth = 500;  // as per your max width requerment 
    $maxHeight = 250; // as per your max hight requerment 

    if ($size[0] > $maxWidth || $size[1] > $maxHeight)
    {
        unlink($file);
        rmdir("./uploads/temp/".$user."/".$mx."/".$hash."/");
        rmdir("./uploads/temp/".$user."/".$mx."/");
        rmdir("./uploads/temp/".$user."/");

    }
    else
        echo $result= "Image Size is not valid, available sizes are 300x250, 468x60, 320x50, 216x36, 168x28, 300x250, 300x50";
    end if
} else {

   echo $result= "Not valid Image found";
}