How can I check whether or not a file is an image?

image, php

Solution

In addition to `getimagesize()`, you can use `exif_imagetype()`

exif_imagetype() reads the first bytes of an image and checks its signature.

When a correct signature is found, the appropriate constant value will be returned otherwise the return value is FALSE. The return value is the same value that getimagesize() returns in index 2 but exif_imagetype() is much faster.

For both functions, FALSE is returned if the file is not determined to be an image.

Problem

Can I check whether or not a certain file is an image? How can do this in PHP? If the file is not an image, I want to give an alert message.

Original source

Related problems