How can I use getimagesize() with $_FILES['']?

后端 未结 4 1383
清歌不尽
清歌不尽 2021-02-14 11:17

I am doing an image upload handler and I would like it to detect the dimensions of the image that\'s been uploaded by the user.

So I start with:

if (isse         


        
4条回答
  •  梦谈多话
    2021-02-14 12:00

    You can do this as such

    $filename = $_FILES['image']['tmp_name'];
    $size = getimagesize($filename);
    
    // or
    
    list($width, $height) = getimagesize($filename);
    // USAGE:  echo $width; echo $height;
    

    Using the condition combined, here is an example

    if (isset($_FILES['image'])) {
        $filename = $_FILES['image']['tmp_name'];
        list($width, $height) = getimagesize($filename);
        echo $width; 
        echo $height;    
    }
    

提交回复
热议问题