PHP:getimagesize对上传的文件返回false [英] PHP: getimagesize returns false for uploaded file

查看:260
本文介绍了PHP:getimagesize对上传的文件返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多类似的问题,但是没有一个解决这个特定的问题. 无论如何,我正在尝试获取上传的图像尺寸,然后再将其保存在服务器上.贝娄是我到目前为止尝试过的代码

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

它输出:

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.

我的PHP版本是7.3.1

推荐答案

与php中的getimagesize一样

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;

这篇关于PHP:getimagesize对上传的文件返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆