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

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

phuonght/mimey
==============

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

v1.0.0(1y ago)0567MITPHPPHP ^8.1

Since Jul 19Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Mimey
=====

[](#mimey)

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

[![Build Status](https://camo.githubusercontent.com/0119d0367305fb27523813b0df64079603e223335e5c60d027ced4a66b9dc58b/68747470733a2f2f7472617669732d63692e6f72672f72616c6f75706869652f6d696d65792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ralouphie/mimey)[![Coverage Status](https://camo.githubusercontent.com/f0d4a5510667adc747cf2cf1c98d86d2752d26cb46ff2d69e7c3bb1e2a64543f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f72616c6f75706869652f6d696d65792f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/ralouphie/mimey?branch=master)[![Code Climate](https://camo.githubusercontent.com/37db12055e26f43da761a71665cb4caeea8aeecc3891786eaacec564aac934c9/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f72616c6f75706869652f6d696d65792f6261646765732f6770612e737667)](https://codeclimate.com/github/ralouphie/mimey)[![Latest Stable Version](https://camo.githubusercontent.com/fbb935c8c4099c16f610dbf68939742d3c726d813dda41c6ed38fbda46f616af/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616c6f75706869652f6d696d65792e737667)](https://packagist.org/packages/ralouphie/mimey)[![Downloads per Month](https://camo.githubusercontent.com/d955defc3367ea745cb98ee1b61f03ee49fa6d7c9c532626d124d24389cbcd7d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f72616c6f75706869652f6d696d65792e737667)](https://packagist.org/packages/ralouphie/mimey)[![License](https://camo.githubusercontent.com/b06def930e753f0a6696ffeec9a77492dd1c1c5b0a0105b42717f632de615486/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72616c6f75706869652f6d696d65792e737667)](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());
```

Install
-------

[](#install)

Compatible with PHP &gt;= 5.4.

```
composer require ralouphie/mimey

```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

660d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f138a7e8fa452cd4350d687a627aceb59edc4438df341b5667b14f15b3f8995?d=identicon)[hoangphuong-dev](/maintainers/hoangphuong-dev)

---

Top Contributors

[![hoangphuong-dev](https://avatars.githubusercontent.com/u/65483795?v=4)](https://github.com/hoangphuong-dev "hoangphuong-dev (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[magepal/magento2-cataloglazyload

Improve the load time of your Magento 2 categories pages by loading your images on demand with our Lazy Load Extension

5563.9k](/packages/magepal-magento2-cataloglazyload)[octopoda/octopus

PHP Sitemap crawler

114.8k](/packages/octopoda-octopus)

PHPackages © 2026

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