Download the PHP package fileeye/mimemap without Composer
On this page you can find all versions of the php package fileeye/mimemap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fileeye/mimemap
More information about fileeye/mimemap
Files in fileeye/mimemap
Package mimemap
Short Description A PHP library to handle MIME Content-Type fields and their related file extensions.
License LGPL-3.0-or-later
Homepage https://github.com/FileEye/MimeMap
Informations about the package mimemap
MimeMap
A PHP library to handle MIME Content-Type fields and their related file extensions.
Features
- Parses MIME Content-Type fields
- Supports the RFC 2045 specification
- Provides utility functions for working with and determining info about MIME types
- Map file extensions to MIME types and vice-versa
- Automatically update the mapping between MIME types and file extensions from the most authoritative sources available, Apache's documentation and the freedesktop.org project.
- PHPUnit tested, 100% test coverage
- PHPStan tested, level 9
- Psalm tested
Credits
MimeMap is a fork of PEAR's MIME_Type package. See all the original contributors.
Note that in comparison with PEAR's MIME_Type, this library has a different scope, mainly focused on finding the mapping between each MIME type and its generally accepted file extensions. Features to detect the MIME type of a file have been removed. The symfony/http-foundation library and its MimeTypeGuesser API are the suggested components to cover that use case.
Alternative packages
MimeMap's main difference from similar packages is that it provides functionalities to use multiple type-to-extension maps and to change the mapping either at runtime or statically in PHP classes. See wgenial/php-mimetyper for a nice list of alternative PHP libraries for MIME type handling.
Installation
Usage
See latest documentation here, automated with phpDocumentor.
Basic
The package comes with a default map that describes MIME types and the file extensions normally associated to each MIME type. The map also stores information about MIME type aliases, (alternative media/subtype combinations that describe the same MIME type), and the descriptions of most MIME types and of the acronyms used.
For example: the MIME type 'application/pdf'
- is described as 'PDF document'
- the PDF acronym is described as 'PDF: Portable Document Format'
- is normally using a file extension 'pdf'
- has aliases such as 'application/x-pdf', 'image/pdf'
The API the package implements is pretty straightforward:
-
You have a MIME type, and want to get the file extensions normally associated to it:
-
Viceversa, you have a file extensions, and want to get the MIME type normally associated to it:
-
You have a raw MIME Content-Type string and want to add a parameter:
- You have a MIME Content-Type string and want to add the type's description as a comment:
Specify alternative MIME type mapping
You can also alter the default map at runtime, either by adding/removing
mappings, or indicating to MimeMap to use a totally different map. The
alternative map must be stored in a PHP class that extends from
\FileEye\MimeMap\Map\AbstractMap
.
-
You want to add an additional MIME type to extension mapping to the default class:
-
You want to set an alternative map class as default:
- You can also use the alternative map just for a single Type or Extension object:
Development
Updating the extension mapping code
The default extension-to-type mapping class can be updated from the sources'
code repositories, using the fileeye-mimemap
utility:
By default, the utility fetches a mapping source available from the Apache's documentation
website, merges it with another mapping source from the freedesktop.org project,
then integrates the result with any overrides specified in the
resources/default_map_build.yml
file, and finally updates the PHP file where
the \FileEye\MimeMap\Map\DefaultMap
class is stored.
The --script
and --class
options allow specifying a different update logic
and a different class file to update. Type
to get more information.