简体   繁体   English

PHP中的getimagesize返回false

[英]getimagesize in php returning false

I am trying to make a web service and in that service, I need people to upload images, but when I try uploading images with the following code, getimagesize returns false. 我正在尝试制作Web服务,在该服务中,我需要人们上传图像,但是当我尝试使用以下代码上传图像时,getimagesize返回false。 What am I doing wrong? 我究竟做错了什么?

HTML: HTML:

<form action="../askcheck.php" method="post" id="ask" enctype="multipart/form-data">
    <div><input type="file" name="photo" id="photo" accept="image/jpg,image/jpeg,image/JPG,image/JPEG,image/png,image/PNG" /></div>
    <div><button type="submit">submit</button></div>

PHP: PHP:

if(is_uploaded_file($_FILES["photo"]["tmp_name"])){
    $check=getimagesize($_FILES["photo"]["tmp_name"]);
    if($check==false){
        //check if the uploaded file is an image    
        $uploadok=0;
        echo 'not an image';
    }
}

When I upload a image, it echos 'not an image'. 当我上传图片时,它会回显“不是图片”。 What am I doing wrong? 我究竟做错了什么? I have tried multiple images. 我尝试了多个图像。

Edited notes: 编辑笔记:

When I echo the GD Version of my server, it gives me 'bundled (2.1.0 compatible)' 当我回显服务器的GD版本时,它给我“捆绑(兼容2.1.0)”的信息

Second Edited notes: The problem is solved, but not in a professional way. 第二次编辑注释:解决了问题,但是不是专业的方法。 I contacted my host about this, and the host did something and told me to try it again, and then it worked. 我联系了我的房东,房东做了一些事情,告诉我再试一次,然后就可以了。 I have no idea what he did, but it must have had to do with some kind of server settings. 我不知道他做了什么,但这一定与某种服务器设置有关。

您可以使用$_FILES['photo']['size']直接获取文件大小,或者如果它是图像大小(如图像的长度和宽度),则可能需要检查GD软件包是否正确加载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM