PHP图像上传检查尺寸

The*_*Kid 2 html php upload image

如何在上传图片后检查图片的尺寸,如果图片与我想要的尺寸不符合,我该怎么办?

所以在挖掘后我发现PHP无法做尺寸.我遵循的解决方案是:

  1. 将文件上传到服务器
  2. 使用新字符串并检查
  3. 如果它与宽度和高度不匹配,请将其删除或继续上传

这是我的代码.有人可以告诉我如何检查当前文件的尺寸以及如果不匹配如何删除文件夹和文件?

# create our temp dir
    mkdir("./uploads/temp/".$user."/".$mx."/".$hash."/", 0777, true);
    # upload dir settup
    $uploaddir='./uploads/temp/'.$user.'/'.$mx.'/'.$hash.'/';
    $file=$uploaddir . basename($_FILES['file']['name']);

    # upload the file first
    if (move_uploaded_file($_FILES['file']['tmp_name'], $file)) {
        # ok so check the height and width
        # if it is not the width and height assigned delete image and folder
        if (image height= and width =){
            unlink($file);
            rmdir($uploaddir);
            $result=0;
        } else {
        # image matches height and width message ok
            $result=1;
        }
    } else {
        # error uploading
        $result=$errormsg;
    }
Run Code Online (Sandbox Code Playgroud)

der*_*aug 6

mkdir("./uploads/temp/".$user."/".$mx."/".$hash."/", 0777, true);
# upload dir settup
$uploaddir='./uploads/temp/'.$user.'/'.$mx.'/'.$hash.'/';
$file=$uploaddir . basename($_FILES['file']['name']);

# upload the file first
if (move_uploaded_file($_FILES['file']['tmp_name'], $file)) {
    # ok so check the height and width
    # if it is not the width and height assigned delete image and folder
    $size = getimagesize($files);
    $maxWidth = 500;
    $maxHeight = 500;
    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
        $result=1;
    end if
} else {
    # error uploading
    $result=$errormsg;
}
Run Code Online (Sandbox Code Playgroud)