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

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

jmoati/mimey
============

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

3.0.1(5y ago)11771MITPHPPHP ^8.0

Since Mar 19Pushed 5y agoCompare

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

READMEChangelogDependencies (3)Versions (14)Used By (1)

Mimey
=====

[](#mimey)

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

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.

The `mime.types` file is parsed by `bin/generate.php` and converted into an optimized PHP array in `mime.types.php`which is then wrapped by helper class `\Mimey\MimeTypes`.

Usage
-----

[](#usage)

```
$mimes = new \Mimey\MimeTypes;

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

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

### 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 = \Mimey\MimeMappingBuilder::create();

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

$mimes = new \Mimey\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 = \Mimey\MimeMappingBuilder::load($cache_file_path);
$mimes = new \Mimey\MimeTypes($builder->getMapping());
```

Install
-------

[](#install)

Compatible with PHP &gt;= 8.0

```
composer require jmoati/mimey

```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 83.7% 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 ~146 days

Recently: every ~361 days

Total

13

Last Release

1953d ago

Major Versions

1.0.8 → 2.0.02018-07-06

2.1.0 → 3.0.02020-12-30

PHP version history (5 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.0

3.0.1PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/798295?v=4)[Jacques Moati](/maintainers/Jmoati)[@Jmoati](https://github.com/Jmoati)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[phpcollection/phpcollection

General-Purpose Collection Library for PHP

1.0k64.0M34](/packages/phpcollection-phpcollection)

PHPackages © 2026

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