mime_content_type -- Detect MIME Content-type for a file
Description
string mime_content_type ( string filename )
Returns the MIME content type for a file as determined by using
information from the magic.mime file.
Content types are returned in MIME format, like text/plain
or application/octet-stream.
Completing <some dude AT somewhere DOT com> comment:
0 string < ? php application/x-httpd-php
and string detection on text files may fail if you check a file encoded with signed UTF-8. The UTF-8 signature is a two bytes code (0xFF 0xFE) that prepends the file in order to force UTF-8 recognition (you may check it on an hexadecimal editor).
The first one may not work if "<?php" is not at the very beginning of your file, e.g., if some HTML preceeds the first bit of PHP code. The second one should work because "<?xml" *should* be the first thing in every XML file.
The function mime_content_type only worked for me on Microsoft Windows after I added the directive "mime_magic.debug" to my php.ini with the value of "On". The default value appears to be "Off". Exampe:
[mime_magic]
mime_magic.debug = On
mime_magic.magicfile = "c:\php\extras\magic.mime"
Note that you will need /bin/sh as well as the file(1) program for this function to work. This is relevant when setting apache up in a chroot-environment. Took me a while to find that out.