PHP mime_content_type() replacement

mime_content_type is not always available depending on your serverThere are various ways to get around it. The current PHP recommendation is to use the Fileinfo (aka finfo) library

An useful alternative is to use exec()

If you know (or are only expecting) that your file is an image you can also use getimagesize(), but this is limited to the image types getimagesize() recognises.]

My preference is the following combination of all three methods, with ‘application/octet-stream’ as a fallback for anything you can’t recognise:

[update 201105302125]

Function updated with more error reporting, including additional debug info if named constant __ADMIN_DEBUG has been set

[/update]

One thought on “PHP mime_content_type() replacement”

Leave a Reply

Your e-mail address will not be published. Required fields are marked *