0

I am using wideimage to manage images uploaded to my application. However, currently I do no validity checking on the documents so the application always assumes what gets uploaded is a valid image document. How can I use wideimage to check if the file is actually an image and not word document renamed to .jpg for example. I have checked the wideimage docs but couldnt find anything.. my detective skills are lacking somewhat so maybe thats why...

Here is the code I use with WideImage:

$image = \WideImage::loadFromFile($new_file);
$splash = $image->resize('600', '600', 'outside');
$splash->saveToFile($dir . '/' . $media_id . '.logo.jpg');
Ozzy
  • 10,285
  • 26
  • 94
  • 138

2 Answers2

2

The function LoadFromFile returns the image object and you can validate the variable $image is an instance of the WideImage_PaletteImage or WideImage_TrueColorImage class.

If that's a valid instance, the uploaded file should be a valid image file.

http://wideimage.sourceforge.net/wp-content/current/doc/WideImage/WideImage.html#methodloadFromFile

Purus
  • 5,701
  • 9
  • 50
  • 89
0

Try this one

if(!exif_imagetype("full_path/image.jpg")) {
   echo "Not a valid image!";
}
Azam Alvi
  • 6,918
  • 8
  • 62
  • 89