PHP: mime_content_type - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Ming (flash) Mimetype

Last updated: Sat, 27 Jan 2007

view this page in

# mime_content_type

(PHP 4 >= 4.3.0, PHP 5)

mime_content_type -- Detect MIME Content-type for a file (deprecated)

## Описание

string mime_content_type ( string filename )

Returns the MIME content type for a file as determined by using information from the `magic.mime` file.

## Список параметров

`filename`

  Path to the tested file.

## Возвращаемые значения

Returns the content type in MIME format, like `text/plain` or `application/octet-stream`.

## Примечания

Внимание
This function has been deprecated as the PECL extension Fileinfo provides the same functionality (and more) in a much cleaner way.

## Примеры

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

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

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

    image/gif
    text/plain

## Смотрите также

Fileinfo for a replacement

add a note User Contributed Notes
mime_content_type
Quis at IHAVEGOTSPAMENOUGH dot omicidio dot nl
12-Feb-2007 09:28
`<?PHP
function qmimetype($file) {
$ext=array_pop(explode('.',$file));
foreach(file('/usr/local/etc/apache22/mime.types') as $line)
if(preg_match('/^([^#]\S+)\s+.*'.$ext.'.*$/',$line,$m))
return $m[1];
return 'application/octet-stream';
}
?>
Not perfect, but works good enough for me ;)`
tree2054 using hotmail
03-Nov-2006 05:59
`The correct little correction:
exec will return the mime with a newline at the end, the trim() should be called with the result of exec, not the other way around.
<?php
if ( ! function_exists ( 'mime_content_type ' ) )
{
function mime_content_type ( $f )
{
return trim ( exec ('file -bi ' . escapeshellarg ( $f ) ) ) ;
}
}
?>`
15-Oct-2006 07:06
`if you use a transparent 'spacer' GIF i've found it needs to be a around 25x25 for it to register as 'image/gif'. otherwise it's read in as 'text/plain'.`
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.`
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"`
add a note
Ming (flash) Mimetype

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 11:33:19 2007 PST