Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen:
Determining the image type of a file
Mar 04, 2016 @ 17:08:14

In his latest post Rob Allen shows a handy way, making use of the http://php.net/getimagesize function, to determine the image type of a file based on header information returned.

One thing I learnt recently which I probably should have known already is that getimagesize() returns more than just the width and height of the image. [...] However, getimagesize() also returns up to 5 more pieces of information. Interestingly, the data array is a mix of indexed elements and named elements

He gives an example of the output from the function and shows how, using data from the returned array, you can compare constants (IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG) to determine what the image type is. This is a better option than relying on the extension of the file as that can be easily faked.

tagged: image type determine tutorial getimagesize constant

Link: https://akrabat.com/determining-the-image-type-of-a-file-with-getimagesize/


Trending Topics: