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

后端 未结 4 1398
清歌不尽
清歌不尽 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:01

    list($w, $h) = getimagesize($_FILES['image']['tmp_name']);
    

    From the docs:

    Index 0 and 1 contains respectively the width and the height of the image.

    Index 2 is one of the IMAGETYPE_XXX constants indicating the type of the image.

    Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

    So you can just do list() and don't worry about indexes, it should get the info you need :)

提交回复
热议问题