PHP图像上传检查维度

PHP图像上传检查维度,php,html,image,upload,Php,Html,Image,Upload,我如何检查图片上传后的尺寸 如果它与我想要的尺寸不匹配,是否将其删除 因此,在深入研究之后,我发现PHP无法处理维度。我的解决办法如下: 将文件上载到服务器 使用新字符串并检查 删除它或继续上载(如果有) 宽度和高度不匹配 这是我的密码。有人能告诉我如何检查当前文件的尺寸,以及如何删除不匹配的文件夹和文件吗 # create our temp dir mkdir("./uploads/temp/".$user."/".$mx."/".$hash."/", 0777, true);

我如何检查图片上传后的尺寸 如果它与我想要的尺寸不匹配,是否将其删除

因此,在深入研究之后,我发现PHP无法处理维度。我的解决办法如下:

  • 将文件上载到服务器
  • 使用新字符串并检查
  • 删除它或继续上载(如果有) 宽度和高度不匹配
  • 这是我的密码。有人能告诉我如何检查当前文件的尺寸,以及如何删除不匹配的文件夹和文件吗

    # 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;
        }
    
    这个怎么样

    要删除文件夹,它应该是空的。

    我使用函数库

    用法示例:

    list($width, $height, $type, $attr) = @getimagesize($imageUri);
    
    if (($height > 500) && ($width > 500)) {
        throw new Exception(sprintf('Invalid image: %d(h) and %d(w) are not within tolerable range', $height, $width));
    }
    
    使用temp\u文件获取尺寸非常简单

    $image_info = getimagesize($_FILES["file_field_name"]["tmp_name"]);
    $image_width = $image_info[0];
    $image_height = $image_info[1];
    

    请在开头编辑你的帖子,解释你想做什么。不要让我们试图弄明白你的目标是什么。你这么说是什么意思?在深入研究之后,我发现PHP无法实现维度?那么
    getimagesize()
    edited。。我不知道getimagesize-但它不会删除图像文件夹。您能给我举个例子吗?要删除文件,请使用
    unlink()
    它不会删除图像文件夹?那么
    rmdir()
    呢。我认为你需要首先自己重新思考这个问题,如果你在这之后遇到问题,请用正确的代码返回。我更新了我的代码,请你告诉我如何使用“如果高度是某物,而宽度是某物”,使用“获取”函数。其中一些事情你需要自己开始解决,即从已发布的解决方案中读取链接到的文档。使用示例更新帖子。非常感谢。我打了你一顿。我确实检查了一些库,但没有找到一个示例,所以我想了解一下这个示例。通常在PHP文档中找到的关于特定函数的注释都是丰富的信息。通读它们是一种很好的做法,很可能你不是第一个遇到特定情况的人。如果这有帮助,请接受答案。啊。。。你看,当我刚刚更新代码时,我就快到了。所以你必须删除所有目录?一个目录必须是空的才能删除它,请看,在你计划移动它们之前,你应该先检查图像尺寸。如果尺寸不正确,请不要移动它们,它们将在脚本结束时被删除。
    $image_info = getimagesize($_FILES["file_field_name"]["tmp_name"]);
    $image_width = $image_info[0];
    $image_height = $image_info[1];