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

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

xantios/mimey
=============

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

v2.2.0(4y ago)332.6M↓17.5%[1 issues](https://github.com/Xantios/mimey/issues)18MITPHPPHP &gt;=7.0

Since Mar 19Pushed 4y agoCompare

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

READMEChangelog (2)Dependencies (2)Versions (15)Used By (18)

Mimey
=====

[](#mimey)

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

[![Build Status](https://camo.githubusercontent.com/c853b8aa42f1c07c1d08c78348d72dea6db90dab5ab016000093bccda971fa2e/68747470733a2f2f7777772e7472617669732d63692e636f6d2f58616e74696f732f6d696d65792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/xantios/mimey)[![Maintainability](https://camo.githubusercontent.com/d5e5fa711ce6cb9a655ada913b4593ffb016e45dd195e4b60cfa6c7e03c54066/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31663865333232643263373361313661313833302f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Xantios/mimey/)[![Latest Stable Version](https://camo.githubusercontent.com/378ab8017edb408d5d59ea9ac43d6525373ea86a501887d5166ebd9cce15bb20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f78616e74696f732f6d696d65792e737667)](https://packagist.org/packages/xantios/mimey)[![Downloads per Month](https://camo.githubusercontent.com/b63b91e2c9784fc86c1d6d849d2733f6aeb37acd194e5b0453677618438a682c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f78616e74696f732f6d696d65792e737667)](https://packagist.org/packages/xantios/mimey)[![License](https://camo.githubusercontent.com/c15fd4e15f6db5ac377ef6a1f36d411d341df540e55ca730856501d71ad31ac8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f78616e74696f732f6d696d65792e737667)](https://packagist.org/packages/ralouphie/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.

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());
```

#### Programmatically or manually add custom type mappings

[](#programmatically-or-manually-add-custom-type-mappings)

You can rename the included `mime.types.custom.example` to `mime.types.custom` and recompile. the custom entries always take precedence over built-in defitions.

#### Updating (advanced)

[](#updating-advanced)

In case there is a update in the httpd defined types you can run `bin/pull.php` in this repo to pull new mime files and compile them

Install
-------

[](#install)

Compatible with PHP &gt;= 5.4.

```
composer require xantios/mimey

```

Credits
-------

[](#credits)

Original version created by rodolfoberrios

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity50

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 80% 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 ~159 days

Recently: every ~399 days

Total

13

Last Release

1801d ago

Major Versions

1.0.8 → 2.0.02018-07-06

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

1.0.3PHP ^5.3|^7.0

2.0.0PHP ^5.4|^7.0

v2.1.1PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1507836?v=4)[Xantios Krugor](/maintainers/xantios)[@Xantios](https://github.com/Xantios)

---

Top Contributors

[![ralouphie](https://avatars.githubusercontent.com/u/1500005?v=4)](https://github.com/ralouphie "ralouphie (36 commits)")[![Xantios](https://avatars.githubusercontent.com/u/1507836?v=4)](https://github.com/Xantios "Xantios (2 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)")[![chriskonnertz](https://avatars.githubusercontent.com/u/4319323?v=4)](https://github.com/chriskonnertz "chriskonnertz (1 commits)")[![rodber](https://avatars.githubusercontent.com/u/20590102?v=4)](https://github.com/rodber "rodber (1 commits)")[![sik0r](https://avatars.githubusercontent.com/u/26262044?v=4)](https://github.com/sik0r "sik0r (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![coopers98](https://avatars.githubusercontent.com/u/116313?v=4)](https://github.com/coopers98 "coopers98 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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