eric01 eric01 - 3 months ago 8
PHP Question

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

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?

Thanks a lot

Answer

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;    
}
Comments