0

I have a code which prints logos. The code checks if a file is an image or not.

Currently I'm using this code.

if(@is_array(getimagesize($mediapath))){
    $image = true;
} else {
    $image = false;
}

But my probems is that this is not very efficient. Maybe It's because it's logos from a external url, or maybe there is a more efficient way.

Any thoughts?

Edvard Åkerberg
  • 2,181
  • 1
  • 26
  • 47
  • 2
    Possible duplicate of [PHP check if file is an image](http://stackoverflow.com/questions/15408125/php-check-if-file-is-an-image) – pes502 Jun 20 '16 at 07:46

2 Answers2

0

Use Below Function for check image.

int exif_imagetype ( string $filename )

URL: http://php.net/manual/en/function.exif-imagetype.php

Virag Shah
  • 64
  • 2
0

Try this.

$info = getimagesize($_FILES['ImageFile']['tmp_name']);
if ($info === FALSE) {
   die("Unable to determine image type of uploaded file");  
}
if (($info[2] !== IMAGETYPE_GIF) && ($info[2] !== IMAGETYPE_JPEG) && ($info[2] !== IMAGETYPE_PNG)) {
    die("Not a gif/jpeg/png");
}