mime_content_type

(PHP 4 >= 4.3.0, PHP 5)

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.

Пример 1. mime_content_type() example

<?php
echo mime_content_type('php.gif') . "\n";
echo
mime_content_type('test.php');
?>

Результат выполнения данного примера:

image/gif
text/plain



mime_content_type
sven at frontmedia dot it
05-Mar-2006 12:58
little correction:

<?php

if ( ! function_exists ( 'mime_content_type ' ) )
{
   function
mime_content_type ( $f )
   {
       return
system ( trim( 'file -bi ' . escapeshellarg ( $f ) ) ) ;
   }
}

?>
webmaster at cafe-clope dot net
23-Feb-2006 05:31
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).
Y0Gi
25-Jan-2006 11:13
The 'file' utility fortunately is available for Windows, too:
http://gnuwin32.sourceforge.net/packages/file.htm
some dude AT somewhere DOT com
07-Oct-2005 09:44
I added these two lines to my magic.mime file:

0 string \<?php application/x-httpd-php
0 string
<?xml text/xml

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.
priyagnair at yahoo dot com
07-Sep-2005 04:40
Quote:
>>sunfra at firenze dot net
>>29-Apr-2005 06:31

mimetype Full list Ref: http://www.duke.edu/websrv/file-extensions.html
ginnsu at arcee dot ca
08-Mar-2005 10:14
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"
Cooljay
08-Nov-2004 06:22
This works on windows too. Make sure to uncomment the following in your php.ini file:
extension=php_mime_magic.dll

Also make sure to add the following line anywhere inside the php.ini file:
mime_magic.magicfile = "C:\path\to\php\install\magic.mime"

Voila working mime content types in windows :)
Sven Riedel
10-Jul-2004 06:17
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.

<MimetypeMing (flash)>
 Last updated: Tue, 15 Nov 2005