mime_content_type

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

mime_content_typeDetect MIME Content-type for a file

Description

mime_content_type(resource|string $filename): string|false

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

Parameters

filename

Path to the tested file.

Return Values

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

Errors/Exceptions

Upon failure, an E_WARNING is emitted.

Examples

Example #1 mime_content_type() Example

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

The above example will output:

image/gif
text/plain

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top