PHP: getimagesize returns false for uploaded file

2019-08-21 07:35发布

问题:

I know there are many similar questions but none of them addresses this particular problem. Anyway, I'm trying to get the uploaded image dimensions before getting it saved on the server. Bellow is the code that I tried so far

print_r($_FILES);
$temp = getimagesize($_FILES['aaiu_upload_file']['tmp_name']);
print_r($temp);
var_dump($temp);

it outputs:

Array
(
    [aaiu_upload_file] => Array
        (
            [name] => Screenshot_4.png
            [type] => image/png
            [tmp_name] => /home/username/tmp/phpN4uRRA
            [error] => 0
            [size] => 19765
        )

)

bool(false)

So, is there something I'm doing wrong? your help is highly appreciated.

My PHP Version is 7.3.1

回答1:

As in php getimagesize Manual

use this to get image dimension :

list($width, $height, $type, $attr) = getimagesize($_FILES['aaiu_upload_file']['tmp_name']);
echo $width.'x'.$height;