Documentation

Horde_Mime_Magic
in package

Utilities to determine MIME content-types of unknown content.

Tags
author

Anil Madhavapeddy anil@recoil.org

author

Michael Slusarz slusarz@horde.org

category

Horde

copyright

1999-2017 Horde LLC

license

http://www.horde.org/licenses/lgpl21 LGPL 2.1

Table of Contents

$_map  : array<string|int, mixed>
The MIME extension map.
analyzeData()  : mixed
Attempt to determine the MIME type of an unknown byte stream.
analyzeFile()  : mixed
Attempt to determine the MIME type of an unknown file.
extToMime()  : string
Attempt to convert a file extension to a MIME type, based on the global Horde and application specific config files.
filenameToMime()  : string
Attempt to convert a filename to a MIME type, based on the global Horde and application specific config files.
mimeToExt()  : string
Attempt to convert a MIME type to a file extension, based on the global Horde and application specific config files.
_getMimeExtensionMap()  : array<string|int, mixed>
Returns a copy of the MIME extension map.

Properties

$_map

The MIME extension map.

protected static array<string|int, mixed> $_map = \null

Methods

analyzeData()

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

public static analyzeData(string $data[, string $magic_db = null ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$data : string

The file data to analyze.

$magic_db : string = null

Path to the mime magic database.

$opts : array<string|int, mixed> = array()

Additional options:

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

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

analyzeFile()

Attempt to determine the MIME type of an unknown file.

public static analyzeFile(string $path[, string $magic_db = null ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$path : string

The path to the file to analyze.

$magic_db : string = null

Path to the mime magic database.

$opts : array<string|int, mixed> = array()

Additional options:

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

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

extToMime()

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

public static extToMime(string $ext) : string

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
$ext : string

The file extension to be mapped to a MIME type.

Return values
string

The MIME type of the file extension.

filenameToMime()

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

public static filenameToMime(string $filename[, bool $unknown = true ]) : string
Parameters
$filename : string

The filename to be mapped to a MIME type.

$unknown : bool = true

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

Return values
string

The MIME type of the filename.

mimeToExt()

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

public static mimeToExt(string $type) : string

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

Parameters
$type : string

The MIME type to be mapped to a file extension.

Return values
string

The file extension of the MIME type.

_getMimeExtensionMap()

Returns a copy of the MIME extension map.

protected static _getMimeExtensionMap() : array<string|int, mixed>
Return values
array<string|int, mixed>

The MIME extension map.

Search results