PHPackages                             fileeye/mimemap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. fileeye/mimemap

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

fileeye/mimemap
===============

A PHP library to handle MIME Content-Type fields and their related file extensions.

2.2.5(1mo ago)259.2M—8.8%2[1 PRs](https://github.com/FileEye/MimeMap/pulls)8LGPL-3.0-or-laterPHPPHP &gt;=8.1CI passing

Since Jan 17Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/FileEye/MimeMap)[ Packagist](https://packagist.org/packages/fileeye/mimemap)[ Docs](https://github.com/FileEye/MimeMap)[ RSS](/packages/fileeye-mimemap/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (39)Used By (8)

MimeMap
=======

[](#mimemap)

[![Tests](https://github.com/FileEye/MimeMap/actions/workflows/php-unit.yml/badge.svg)](https://github.com/FileEye/MimeMap/actions/workflows/php-unit.yml)[![PHPStan level](https://camo.githubusercontent.com/54869e099958dc64c6511b075e4b5516c2f4b29f8ee7e269c4ffc617e75940eb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2532306c6576656c2d6d61782d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/FileEye/MimeMap/actions/workflows/code-quality.yml)[![codecov](https://camo.githubusercontent.com/ee34482ebe115b4dd8821ea26b839cb6f6cd745a61640342d2d8b8b22ad75792/68747470733a2f2f636f6465636f762e696f2f67682f46696c654579652f4d696d654d61702f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d5355414d4e4b5a4c4557)](https://codecov.io/gh/FileEye/MimeMap)[![Latest Stable Version](https://camo.githubusercontent.com/bdc396519894a5197db23a9135495e7b5b18319901ac1e7d7e2aeec8f75d8efe/68747470733a2f2f706f7365722e707567782e6f72672f66696c656579652f6d696d656d61702f762f737461626c65)](https://packagist.org/packages/fileeye/mimemap)[![Total Downloads](https://camo.githubusercontent.com/80d7962a532be854dc3fd9558f845eea575f40a18be8622b1e0271b1a582d366/68747470733a2f2f706f7365722e707567782e6f72672f66696c656579652f6d696d656d61702f646f776e6c6f616473)](https://packagist.org/packages/fileeye/mimemap)[![License](https://camo.githubusercontent.com/82fb6ae9057215385daa1cba68cf980f18de3b7a3901801719d332bab2ff486f/68747470733a2f2f706f7365722e707567782e6f72672f66696c656579652f6d696d656d61702f6c6963656e7365)](https://packagist.org/packages/fileeye/mimemap)

A PHP library to handle MIME Content-Type fields and their related file extensions.

Features
--------

[](#features)

- Parses MIME Content-Type fields
- Supports the [RFC 2045](https://www.ietf.org/rfc/rfc2045.txt) 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](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=log)and the [freedesktop.org project](http://freedesktop.org).
- PHPUnit tested, 100% test coverage
- PHPStan tested, level 10

Credits
-------

[](#credits)

MimeMap is a fork of PEAR's [MIME\_Type](https://github.com/pear/MIME_Type) package. See all the [original contributors](https://github.com/pear/MIME_Type/graphs/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](https://github.com/symfony/http-foundation)library and its [MimeTypeGuesser](https://api.symfony.com/master/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.html)API are the suggested components to cover that use case.

### Alternative packages

[](#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](https://github.com/wgenial/php-mimetyper#other-php-libraries-for-mime-types)for a nice list of alternative PHP libraries for MIME type handling.

Installation
------------

[](#installation)

```
$ composer require fileeye/mimemap

```

Usage
-----

[](#usage)

See latest documentation [here](https://fileeye.github.io/MimeMap/), automated with phpDocumentor.

### Basic

[](#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:

1. You have a MIME type, and want to get the file extensions normally associated to it:

```
use FileEye\MimeMap\Type;
...
$type = new Type('image/jpeg');

print_r($type->getExtensions());
// will print ['jpeg', 'jpg', 'jpe']

print_r($type->getDefaultExtension());
// will print 'jpeg'

// When passing an alias to a MIME type, the API will
// return the extensions to the parent type:
$type = new Type('image/pdf');

print_r($type->getDefaultExtension());
// will print 'pdf' which is the default extension for 'application/pdf'
```

2. Viceversa, you have a file extensions, and want to get the MIME type normally associated to it:

```
use FileEye\MimeMap\Extension;
...
$ext = new Extension('xar');

print_r($ext->getTypes());
// will return ['application/vnd.xara', 'application/x-xar']

print_r($ext->getDefaultType());
// will return 'application/vnd.xara'
```

3. You have a raw MIME Content-Type string and want to add a parameter:

```
use FileEye\MimeMap\Type;
...
$type = new Type('text / (Unstructured text)  plain  ; charset = (UTF8, not ASCII) utf-8');
$type->addParameter('lang', 'it', 'Italian');

echo $type->toString(Type::SHORT_TEXT);
// will print 'text/plain'

echo $type->toString(Type::FULL_TEXT);
// will print 'text/plain; charset="utf-8"; lang="it"'

echo $type->toString(Type::FULL_TEXT_WITH_COMMENTS);
// will print 'text/plain (Unstructured text); charset="utf-8" (UTF8, not ASCII), lang="it" (Italian)'
```

4. You have a MIME Content-Type string and want to add the type's description as a comment:

```
use FileEye\MimeMap\Type;
...
$type = new Type('text/html');

$type_desc = $type->getDescription();
$type->setSubTypeComment($type_desc);
echo $type->toString(Type::FULL_TEXT_WITH_COMMENTS);
// will print 'text/html (HTML document)'

// Setting the $include_acronym parameter of getDescription to true
// will extend the description to include the meaning of the acronym
$type_desc = $type->getDescription(true);
$type->setSubTypeComment($type_desc);
echo $type->toString(Type::FULL_TEXT_WITH_COMMENTS);
// will print 'text/html (HTML document, HTML: HyperText Markup Language)'
```

### Specify alternative MIME type mapping

[](#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`.

1. You want to add an additional MIME type to extension mapping to the default class:

```
use FileEye\MimeMap\Extension;
use FileEye\MimeMap\MapHandler;
use FileEye\MimeMap\Type;
...
$map = MapHandler::map();
$map->addTypeExtensionMapping('foo/bar', 'baz');

$type = new Type('foo/bar');
$default_extension = $type->getDefaultExtension();
// will return 'baz'

$ext = new Extension('baz');
$default_type = $ext->getDefaultExtension();
// will return 'foo/bar'
```

2. You want to set an alternative map class as default:

```
use FileEye\MimeMap\Extension;
use FileEye\MimeMap\MapHandler;
use FileEye\MimeMap\Type;
...
MapHandler::setDefaultMapClass('MyProject\MyMap');
...
```

3. You can also use the alternative map just for a single Type or Extension object:

```
use FileEye\MimeMap\Extension;
use FileEye\MimeMap\Type;
...
$type = new Type('foo/bar', 'MyProject\MyMap');
$ext = new Extension('baz', 'MyProject\MyMap');
```

Development
-----------

[](#development)

### Updating the extension mapping code

[](#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:

```
$ cd [project_directory]/vendor/bin
$ fileeye-mimemap update

```

By default, the utility fetches a mapping source available from the [Apache's documentation](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co)website, merges it with another mapping source from the [freedesktop.org project](https://gitlab.freedesktop.org/xdg/shared-mime-info/-/blob/master/data/freedesktop.org.xml.in), 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

```
$ fileeye-mimemap update --help

```

to get more information.

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance85

Actively maintained with recent releases

Popularity54

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~72 days

Recently: every ~115 days

Total

37

Last Release

57d ago

Major Versions

1.2.x-dev → 2.0.0-beta12022-05-14

PHP version history (5 changes)1.0.0-alpha1PHP &gt;=5.4

1.2.0PHP &gt;=5.6

2.0.0-beta1PHP &gt;=7.3

2.1.0PHP &gt;=7.4

2.2.0-rc1PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1174864?v=4)[mondrake](/maintainers/mondrake)[@mondrake](https://github.com/mondrake)

---

Top Contributors

[![mondrake](https://avatars.githubusercontent.com/u/1174864?v=4)](https://github.com/mondrake "mondrake (172 commits)")[![devenjahnke](https://avatars.githubusercontent.com/u/10586846?v=4)](https://github.com/devenjahnke "devenjahnke (1 commits)")

---

Tags

mimemime-databasemime-parsermime-typemime-typesphpmimemime-typemime-parsermime-database

### Embed Badge

![Health badge](/badges/fileeye-mimemap/health.svg)

```
[![Health](https://phpackages.com/badges/fileeye-mimemap/health.svg)](https://phpackages.com/packages/fileeye-mimemap)
```

###  Alternatives

[symfony/mime

Allows manipulating MIME messages

2.8k668.8M911](/packages/symfony-mime)[zbateson/mail-mime-parser

MIME email message parser

54149.2M79](/packages/zbateson-mail-mime-parser)[php-mime-mail-parser/php-mime-mail-parser

A fully tested email parser for PHP 8.0+ (mailparse extension wrapper).

9979.6M27](/packages/php-mime-mail-parser-php-mime-mail-parser)[nette/mail

📧 Nette Mail: A handy library for creating and sending emails in PHP.

5389.8M246](/packages/nette-mail)[zbateson/stream-decorators

PHP psr7 stream decorators for mime message part streams

4748.6M6](/packages/zbateson-stream-decorators)[rosell-dk/image-mime-type-guesser

Guess mime type of images

108.0M5](/packages/rosell-dk-image-mime-type-guesser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
