PHPackages                             esi/mimey - 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. esi/mimey

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

esi/mimey
=========

PHP package for converting file extensions to MIME types and vice versa.

v2.1.0(2y ago)17.2k—2.1%1[1 issues](https://github.com/ericsizemore/mimey/issues)MITPHPPHP ^8.2 &lt;8.5CI failing

Since Jul 8Pushed 4d agoCompare

[ Source](https://github.com/ericsizemore/mimey)[ Packagist](https://packagist.org/packages/esi/mimey)[ Fund](https://ko-fi.com/ericsizemore)[ GitHub Sponsors](https://github.com/ericsizemore)[ RSS](/packages/esi-mimey/feed)WikiDiscussions develop Synced 2d ago

READMEChangelog (7)Dependencies (10)Versions (15)Used By (0)

Mimey
=====

[](#mimey)

PHP package for converting file extensions to MIME types and vice versa.

[![Build Status](https://camo.githubusercontent.com/1c8dbc686d3dccad523a5ba0f9395a888fc59e094bd2f8fe42ba2f36325cc4b8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f6d696d65792f6261646765732f6275696c642e706e673f623d646576656c6f70)](https://scrutinizer-ci.com/g/ericsizemore/mimey/build-status/develop)[![Code Coverage](https://camo.githubusercontent.com/4e0bfa3c68b4c0324921dd88354273e40c41045789ba3284694677254f599597/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f6d696d65792f6261646765732f636f7665726167652e706e673f623d646576656c6f70)](https://scrutinizer-ci.com/g/ericsizemore/mimey/?branch=develop)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2f0610d185e26fdee3e029de9c512c974b9fe145426db2f96d9bae2499cb62b8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f6d696d65792f6261646765732f7175616c6974792d73636f72652e706e673f623d646576656c6f70)](https://scrutinizer-ci.com/g/ericsizemore/mimey/?branch=develop)[![Continuous Integration](https://github.com/ericsizemore/mimey/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/ericsizemore/mimey/actions/workflows/continuous-integration.yml)[![Type Coverage](https://camo.githubusercontent.com/3e3eae7313edafaf23e3fa8f20169b3b8fcbdcc3f9847003a0db698b5ec90db5/68747470733a2f2f73686570686572642e6465762f6769746875622f6572696373697a656d6f72652f6d696d65792f636f7665726167652e737667)](https://shepherd.dev/github/ericsizemore/mimey)[![Psalm Level](https://camo.githubusercontent.com/33087bf90b9a71824bb5938947a17cce7f03f9c280b0f49717f3a3a5783e1177/68747470733a2f2f73686570686572642e6465762f6769746875622f6572696373697a656d6f72652f6d696d65792f6c6576656c2e737667)](https://shepherd.dev/github/ericsizemore/mimey)[![SymfonyInsight](https://camo.githubusercontent.com/6ce4219f4a348e521904c84d2c4cb47f208c929257157386fe3088708d2ed1e2/68747470733a2f2f696e73696768742e73796d666f6e792e636f6d2f70726f6a656374732f31616134336333392d373766652d343533632d393861612d3737303837643733343139352f6d696e692e737667)](https://insight.symfony.com/projects/1aa43c39-77fe-453c-98aa-77087d734195)[![Quality Gate Status](https://camo.githubusercontent.com/2cdc8aebd1d448023e0d1c052fa0b8abcbc7fc602d81756df96262cff0446c83/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6572696373697a656d6f72655f6d696d6579266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=ericsizemore_mimey)[![Latest Stable Version](https://camo.githubusercontent.com/b877d14f0064d0dfb38dc9bbcc062bf17534eb9c3d45d284f1b3cbddff96aa23/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6573692f6d696d65792e737667)](https://packagist.org/packages/esi/mimey)[![Downloads per Month](https://camo.githubusercontent.com/27f968489b5636f027ecc00b7cabf08816063735af29f5a0111cace28462e5f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6573692f6d696d65792e737667)](https://packagist.org/packages/esi/mimey)[![License](https://camo.githubusercontent.com/f172e58f615fb4586a5744d5f626ab27864e27c477d7f9accf59c7412d26a39b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6573692f6d696d65792e737667)](https://packagist.org/packages/esi/mimey)

This package uses [httpd](https://httpd.apache.org/docs/current/programs/httpd.html)'s [mime.types](https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types) to generate a mapping of file extension to MIME type and the other way around. Click here to view the changelog from their svn: [changelog](https://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=log)

The `mime.types` file is parsed by `bin/generate.php` and converted into an optimized JSON object in `dist/mime.types.min.json`which is then wrapped by helper class `MimeTypes`.

Also provides a generated PHP enum with all mime types and methods to get the extension. Can also be used to get the enum value from an extension.

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

[](#installation)

Compatible with PHP &gt;= 8.2 and can be installed with [Composer](https://getcomposer.org).

```
$ composer require esi/mimey
```

Usage
-----

[](#usage)

```
$mimes = new MimeTypes;

// Convert extension to MIME type:
$mimes->getMimeType('json'); // application/json

// Convert MIME type to extension:
$mimes->getExtension('application/json'); // json
```

### Using the enum

[](#using-the-enum)

```
$json = MimeType::ApplicationJson;
echo $json->getExtension(); // json
echo $json->value; // application/json

$html = MimeType::fromExtension('html');
echo $html->value; // text/html

MimeType::fromExtension('asdf'); // throws an InvalidArgumentException if the extension cannot be found
```

### Getting All

[](#getting-all)

It's rare, but some extensions have multiple MIME types:

```
// Get all MIME types for an extension:
$mimes->getAllMimeTypes('wmz'); // array('application/x-ms-wmz', 'application/x-msmetafile')
```

However, there are many MIME types that have multiple extensions:

```
// Get all extensions for a MIME type:
$mimes->getAllExtensions('image/jpeg'); // array('jpeg', 'jpg', 'jpe')
```

### Custom Conversions

[](#custom-conversions)

You can add custom conversions by changing the mapping that is given to `MimeTypes`.

There is a `Mapping\Builder` that can help with this:

```
use Esi\Mimey\Mapping\Builder;

// Create a builder using the built-in conversions as the basis.
$builder = Builder::create();

// Add a conversion. This conversion will take precedence over existing ones.
$builder->add('custom/mime-type', 'myextension');

$mimes = new MimeTypes($builder->getMapping());
$mimes->getMimeType('myextension'); // custom/mime-type
$mimes->getExtension('custom/mime-type'); // myextension
```

You can add as many conversions as you would like to the builder:

```
$builder->add('custom/mime-type', 'myextension');
$builder->add('foo/bar', 'foobar');
$builder->add('foo/bar', 'fbar');
$builder->add('baz/qux', 'qux');
$builder->add('cat/qux', 'qux');
...
```

#### Optimized Custom Conversion Loading

[](#optimized-custom-conversion-loading)

You can optimize the loading of custom conversions by saving all conversions to a compiled PHP file as part of a build step.

```
// Add a bunch of custom conversions.
$builder->add(...);
$builder->add(...);
$builder->add(...);
...
// Save the conversions to a cached file.
$builder->save($cacheFilePath);
```

The file can then be loaded to avoid overhead of repeated `$builder->add(...)` calls:

```
// Load the conversions from a cached file.
$builder = Builder::load($cacheFilePath);
$mimes = new MimeTypes($builder->getMapping());
```

About
-----

[](#about)

### Requirements

[](#requirements)

- Mimey works with PHP 8.2.0 or above.

Credits
-------

[](#credits)

- Author: [Eric Sizemore](https://github.com/ericsizemore)
- Thanks to [all Contributors](https://github.com/ericsizemore/mimey/contributors).

`Esi\Mimey` would not be possible without the wonderful work of the libraries that came before it, which it is forked from:

- [elephox-dev/mimey](https://github.com/elephox-dev/mimey) by [Ricardo Boss](https://github.com/ricardoboss).
- [ralouphie/mimey](https://github.com/ralouphie/mimey) by [Ralph Khattar](https://github.com/ralouphie).

My thanks to them, and all their contributors. To view changes in this library in comparison to the original library, please see the [CHANGELOG.md](./CHANGELOG.md) file.

Contributing
------------

[](#contributing)

Missing a MIME type?

Open an issue or even add it yourself! The process is very easy:

1. fork this repository
2. add your MIME type to the `data/mime.types.custom` file (make sure it's properly formatted!)
3. push your changes
4. submit a pull request

See [CONTRIBUTING](./CONTRIBUTING.md) for more information.

Bugs and feature requests are tracked on [GitHub](https://github.com/ericsizemore/mimey/issues).

### Contributor Covenant Code of Conduct

[](#contributor-covenant-code-of-conduct)

See [CODE\_OF\_CONDUCT.md](./CODE_OF_CONDUCT.md)

### Backward Compatibility Promise

[](#backward-compatibility-promise)

See [backward-compatibility.md](./backward-compatibility.md) for more information on Backwards Compatibility.

### Changelog

[](#changelog)

See the [CHANGELOG](./CHANGELOG.md) for more information on what has changed recently.

### License

[](#license)

See the [LICENSE](./LICENSE.md) for more information on the license that applies to this project.

### Security

[](#security)

See [SECURITY](./SECURITY.md) for more information on the security disclosure process.

### Upgrading

[](#upgrading)

See [UPGRADING](./UPGRADING.md) for more information on the upgrade process.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance45

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 54.2% 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 ~70 days

Total

8

Last Release

596d ago

Major Versions

v1.2.0 → v2.0.02024-04-07

PHP version history (4 changes)v1.0.0PHP ^8.1 &lt;8.3

v1.1.0PHP ^8.1

v1.1.1PHP ^8.1 &lt;8.5

v1.2.0PHP ^8.2 &lt;8.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/723810?v=4)[Eric Sizemore](/maintainers/ericsizemore)[@ericsizemore](https://github.com/ericsizemore)

---

Top Contributors

[![ericsizemore](https://avatars.githubusercontent.com/u/723810?v=4)](https://github.com/ericsizemore "ericsizemore (436 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (261 commits)")[![ricardoboss](https://avatars.githubusercontent.com/u/6266356?v=4)](https://github.com/ricardoboss "ricardoboss (40 commits)")[![ralouphie](https://avatars.githubusercontent.com/u/1500005?v=4)](https://github.com/ralouphie "ralouphie (36 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (24 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![chriskonnertz](https://avatars.githubusercontent.com/u/4319323?v=4)](https://github.com/chriskonnertz "chriskonnertz (1 commits)")[![sik0r](https://avatars.githubusercontent.com/u/26262044?v=4)](https://github.com/sik0r "sik0r (1 commits)")[![coopers98](https://avatars.githubusercontent.com/u/116313?v=4)](https://github.com/coopers98 "coopers98 (1 commits)")[![danielindiano](https://avatars.githubusercontent.com/u/553232?v=4)](https://github.com/danielindiano "danielindiano (1 commits)")[![fossabot](https://avatars.githubusercontent.com/u/29791463?v=4)](https://github.com/fossabot "fossabot (1 commits)")[![janakael89](https://avatars.githubusercontent.com/u/16027359?v=4)](https://github.com/janakael89 "janakael89 (1 commits)")

---

Tags

apache-mimetypesfile-mime-typehacktoberfestmimemime-typemime-typesmimemime-typemime-typesapache-mimetypesfile-mime-type

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/esi-mimey/health.svg)

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

###  Alternatives

[symfony/mime

Allows manipulating MIME messages

2.8k716.9M1.4k](/packages/symfony-mime)[zbateson/mail-mime-parser

MIME email message parser

54753.3M91](/packages/zbateson-mail-mime-parser)[php-mime-mail-parser/php-mime-mail-parser

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

1.0k10.4M35](/packages/php-mime-mail-parser-php-mime-mail-parser)[nette/mail

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

54010.2M282](/packages/nette-mail)[fileeye/mimemap

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

269.9M19](/packages/fileeye-mimemap)[zbateson/stream-decorators

PHP psr7 stream decorators for mime message part streams

4752.6M9](/packages/zbateson-stream-decorators)

PHPackages © 2026

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