简体   繁体   中英

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. What am I doing wrong?

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:

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)'

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软件包是否正确加载

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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