\Horde_Mime_Magic

Utilities to determine MIME content-types of unknown content.

Summary

Methods
Properties
Constants
extToMime()
filenameToMime()
mimeToExt()
analyzeFile()
analyzeData()
No public properties found
No constants found
_getMimeExtensionMap()
$_map
N/A
No private methods found
No private properties found
N/A

Properties

$_map

$_map : array

The MIME extension map.

Type

array

Methods

extToMime()

extToMime(string  $ext) : string

Attempt to convert a file extension to a MIME type, based on the global Horde and application specific config files.

If we cannot map the file extension to a specific type, then we fall back to a custom MIME handler 'x-extension/$ext', which can be used as a normal MIME type internally throughout Horde.

Parameters

string $ext

The file extension to be mapped to a MIME type.

Returns

string —

The MIME type of the file extension.

filenameToMime()

filenameToMime(string  $filename, boolean  $unknown = true) : string

Attempt to convert a filename to a MIME type, based on the global Horde and application specific config files.

Parameters

string $filename

The filename to be mapped to a MIME type.

boolean $unknown

How should unknown extensions be handled? If true, will return 'x-extension/*' types. If false, will return 'application/octet-stream'.

Returns

string —

The MIME type of the filename.

mimeToExt()

mimeToExt(string  $type) : string

Attempt to convert a MIME type to a file extension, based on the global Horde and application specific config files.

If we cannot map the type to a file extension, we return false.

Parameters

string $type

The MIME type to be mapped to a file extension.

Returns

string —

The file extension of the MIME type.

analyzeFile()

analyzeFile(string  $path, string  $magic_db = null, array  $opts = array()) : mixed

Attempt to determine the MIME type of an unknown file.

Parameters

string $path

The path to the file to analyze.

string $magic_db

Path to the mime magic database.

array $opts

Additional options:

  • nostrip: (boolean) Don't strip parameter information from MIME type string. DEFAULT: false

Returns

mixed —

The MIME type of the file. Returns false if the file type can not be determined.

analyzeData()

analyzeData(string  $data, string  $magic_db = null, array  $opts = array()) : mixed

Attempt to determine the MIME type of an unknown byte stream.

Parameters

string $data

The file data to analyze.

string $magic_db

Path to the mime magic database.

array $opts

Additional options:

  • nostrip: (boolean) Don't strip parameter information from MIME type string. DEFAULT: false

Returns

mixed —

The MIME type of the file. Returns false if the file type can not be determined.

_getMimeExtensionMap()

_getMimeExtensionMap() : array

Returns a copy of the MIME extension map.

Returns

array —

The MIME extension map.