PHPackages                             elephox/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. elephox/mimey

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

elephox/mimey
=============

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

4.0.8(7mo ago)16217.1k↓17.8%35MITPHPPHP ^8.1 &lt;9.0CI passing

Since Mar 19Pushed 4mo agoCompare

[ Source](https://github.com/elephox-dev/mimey)[ Packagist](https://packagist.org/packages/elephox/mimey)[ RSS](/packages/elephox-mimey/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (26)Used By (5)

Mimey
=====

[](#mimey)

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

[![Tests](https://github.com/elephox-dev/mimey/actions/workflows/tests.yml/badge.svg)](https://github.com/elephox-dev/mimey/actions/workflows/tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/115744a6351fb55792602a2801a748e756585a61927ba57f945e2681e897cefa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c6570686f782f6d696d65792e737667)](https://packagist.org/packages/elephox/mimey)[![Downloads per Month](https://camo.githubusercontent.com/cf95e892204e235ed523afa0846a3def6cb91841c244881d3518bbf030d62e70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f656c6570686f782f6d696d65792e737667)](https://packagist.org/packages/elephox/mimey)[![License](https://camo.githubusercontent.com/6aaaf295989205b26692fa2ccab18e2291828b6b086152ee83afa8465bb1ab8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f656c6570686f782f6d696d65792e737667)](https://packagist.org/packages/elephox/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`.

**Since 3.1.0:** 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.

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 `MimeMappingBuilder` that can help with this:

```
// Create a builder using the built-in conversions as the basis.
$builder = MimeMappingBuilder::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($cache_file_path);
```

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

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

Install
-------

[](#install)

Compatible with PHP &gt;= 8.1.

```
composer require elephox/mimey

```

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

After a short review and merge, the MIME type will automagically be added to the library.

If you want to, you can also run `composer generate-types` and add the changed files under `dist/` to your PR.

Credits
-------

[](#credits)

This fork uses the same license as the original repository (MIT). This repository is a fork of [ralouphie/mimey](https://github.com/ralouphie/mimey). Thanks to them and all the contributors!

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance70

Regular maintenance activity

Popularity43

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 58.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 ~145 days

Recently: every ~267 days

Total

25

Last Release

222d ago

Major Versions

1.0.8 → 2.0.02018-07-06

2.1.0 → 3.0.02022-02-10

3.1.2 → 4.0.02022-02-11

PHP version history (9 changes)1.0.0PHP &gt;=5.3

1.0.3PHP ^5.3|^7.0

2.0.0PHP ^5.4|^7.0

3.0.0PHP ~8.1 || ~8.2

3.0.1PHP ~8.1.0 || ~8.2.0

4.0.1PHP ^8.1 &lt;8.3

4.0.6PHP ^8.1 &lt;8.4

4.0.7PHP ^8.1 &lt;8.5

4.0.8PHP ^8.1 &lt;9.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ea436f1f084470f9d75ca0fde95e2418ba03d560bc4e20e03171648c123fa80?d=identicon)[ricardoboss](/maintainers/ricardoboss)

---

Top Contributors

[![ricardoboss](https://avatars.githubusercontent.com/u/6266356?v=4)](https://github.com/ricardoboss "ricardoboss (64 commits)")[![ralouphie](https://avatars.githubusercontent.com/u/1500005?v=4)](https://github.com/ralouphie "ralouphie (36 commits)")[![fulopattila122](https://avatars.githubusercontent.com/u/1162360?v=4)](https://github.com/fulopattila122 "fulopattila122 (4 commits)")[![janakael89](https://avatars.githubusercontent.com/u/16027359?v=4)](https://github.com/janakael89 "janakael89 (1 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)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[hyperf/nacos

Nacos SDK

22487.9k10](/packages/hyperf-nacos)

PHPackages © 2026

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