Alex Rivera | Logout

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

Asked 2012-03-21T06:00:16.563
10

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 (isset($_FILES['image'])) etc....

and I have

list($width, $height) = getimagesize(...);

How am i supposed to use them together?

Edit
Report

1 Answer

1
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 :)

answered 2012-03-21T06:03:08.643

Your Answer