How to check if MIME type is JPG, PNG, BMP or GIF?

I wrote this code:

$filename = "some/path/where/the/file/can/be/found.some_extension"; $buffer = file_get_contents($filename); $finfo = new finfo(FILEINFO_MIME_TYPE); var_dump($finfo->buffer($buffer)); finfo_close($finfo); 

Possible outputs:

 "image/jpeg", "image/png", "image/gif", "image/x-ms-bmp" 

I would like to know what are the possible outputs of $finfo->buffer($buffer) if the file is png, gif, bmp or jpg?

I saw here a returnMIMEType , which, for example, will not detect "image/x-ms-bmp" as bmp.

+7
source share
1 answer

We can view the possible types of MIME extensions by searching for the file extension using the link provided by Pitchinnate. For example, BMP MIME types can be found at: filext.com/file-extension/BMP

+1
source

All Articles