Is there any decent way in PHP to get the mime type?
I have been searching extensively the past few hours and it seems like there are three main ways, which each way having problems:
mime_content_type() This is deprecated, alot of the times not installed, and if installed will sometimes not find the mime.magic file.
file_info Wasn't installed on the hosts I tried, doesn't seem to have very good support. Is an extension (PECL).
shell_exec(file -ib . $file) Doesn't work on windows servers. I tried it on a linux server and it gave me "image/x-3ds2" for a php file. What the hell is that!!!
What is a good, almost bullet proof way to get the mime type of a file?
As workaround you can use the "mime.php" extension from http://upgradephp.berlios.de/ It simulates the mime_content_type() if not available. Made specifically for such cases.
You can install your private mime.magic file and force it with ini_set("mime_magic.magicfile"). This is recommended anyway, so you have the desired settings available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With