PHPackages                             devanych/mime-types - 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. devanych/mime-types

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

devanych/mime-types
===================

Converts MIME types to file extensions and vice versa

2.1.2(5y ago)0235.1k—5.7%2MITPHPPHP ^7.4|^8.0

Since Oct 2Pushed 3y ago1 watchersCompare

[ Source](https://github.com/devanych/mime-types)[ Packagist](https://packagist.org/packages/devanych/mime-types)[ RSS](/packages/devanych-mime-types/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (10)Used By (2)

Mime Types
==========

[](#mime-types)

[![License](https://camo.githubusercontent.com/46d86b862efacedfb13f9f5c6a6038304f99fd435d720e7aae55fe5589ba6adf/68747470733a2f2f706f7365722e707567782e6f72672f646576616e7963682f6d696d652d74797065732f6c6963656e7365)](https://packagist.org/packages/devanych/mime-types)[![Latest Stable Version](https://camo.githubusercontent.com/d4b4fe1c4746c7546f91d87e81c7849366881e1e6351eeda2bd010e2a0f92b2a/68747470733a2f2f706f7365722e707567782e6f72672f646576616e7963682f6d696d652d74797065732f76)](https://packagist.org/packages/devanych/mime-types)[![Total Downloads](https://camo.githubusercontent.com/fd40c748d86c080d00f05ed1eb20e2ce22bcc16d9f0b6fda9658dffc088f4185/68747470733a2f2f706f7365722e707567782e6f72672f646576616e7963682f6d696d652d74797065732f646f776e6c6f616473)](https://packagist.org/packages/devanych/mime-types)[![GitHub Build Status](https://github.com/devanych/mime-types/workflows/build/badge.svg)](https://github.com/devanych/mime-types/actions)[![GitHub Static Analysis Status](https://github.com/devanych/mime-types/workflows/static/badge.svg)](https://github.com/devanych/mime-types/actions)[![Scrutinizer Code Coverage](https://camo.githubusercontent.com/b0e94f9ca94c1d59e2af24b7596dfafa255ffd29712aaa488fb3cd754c96aa79/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646576616e7963682f6d696d652d74797065732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/devanych/mime-types/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/34ba6c77dbf96e7358e7c1c8d50ee74bda4790a4258bd0e5f2a4bc6dd7b72bdd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646576616e7963682f6d696d652d74797065732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/devanych/mime-types/?branch=master)

This PHP package allows you to convert MIME types to file extensions and Vice versa, and to add your own MIME types and file extensions.

You can change the functionality by implementing interfaces:

- [Devanych\\Mime\\MimeTypesInterface](https://github.com/devanych/mime-types/blob/master/src/MimeTypesInterface.php) - contains methods to implement the functionality.
- [Devanych\\Mime\\MimeTypesMapsInterface](https://github.com/devanych/mime-types/blob/master/src/MimeTypesMapsInterface.php) - contains a map of MIME types and file extensions.

A guide with a detailed description in Russian language is [available here](https://devanych.ru/development/konvertaciya-mime-tipov-i-rasshirenij-fajlov).

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

[](#installation)

This package requires PHP version 7.4 or later.

```
composer require devanych/mime-types

```

Usage MimeTypes
---------------

[](#usage-mimetypes)

Creation:

```
use Devanych\Mime\MimeTypes;

$mimeTypes = new MimeTypes();
```

Conversion:

```
/**
 * Gets the MIME types for the given file extension.
 *
 * @param string $extension
 * @return string[] an array of MIME types or an empty array if no match is found
 */
$mimeTypes->getMimeTypes('jpeg'); // ['image/jpeg', 'image/pjpeg']

/**
 * Gets the file extensions for the given MIME type.
 *
 * @param string $mimeType
 * @return string[] an array of extensions or an empty array if no match is found
 */
$mimeTypes->getExtensions('image/jpeg'); // ['jpeg', 'jpg', 'jpe']
```

Adding:

```
/**
 * Adds a custom map of MIME types and file extensions.
 *
 * The key is a MIME type and the value is an array of extensions.
 *
 * Example code:
 *
 * $map = [
 *    'image/ico' => ['ico'],
 *    'image/icon' => ['ico'],
 *    'image/jp2' => ['jp2', 'jpg2'],
 *    'image/jpeg' => ['jpeg', 'jpg', 'jpe'],
 *    'image/jpeg2000' => ['jp2', 'jpg2'],
 * ];
 *
 * If the map format is invalid, an `\InvalidArgumentException` will be thrown when the map is added.
 *
 * @param array $map
 */
$mimeTypes->addMap($map);
```

> You can pass a map to the constructor when you create a `Devanych\Mime\MimeTypes` class, inside the constructor calls the `addMap()` method.

Usage MimeTypesAllowed
----------------------

[](#usage-mimetypesallowed)

If you want to use only the allowed preset mime types and file extensions then use the `Devanych\Mime\MimeTypesAllowed` instead of the `Devanych\Mime\MimeTypes`.

```
use Devanych\Mime\MimeTypesAllowed;

$map = [
    'image/gif' => ['gif'],
    'image/png' => ['png'],
    'image/jpeg' => ['jpeg', 'jpg', 'jpe'],
];

$mimeTypes = new MimeTypesAllowed($map);
```

When you create an instance of the `Devanych\Mime\MimeTypesAllowed` class, you MUST pass the map. If you pass an empty or incorrect map, the exception `\InvalidArgumentException` will be thrown.

> When creating an instance of the `Devanych\Mime\MimeTypesAllowed` class, the `addMap()` method is called in the constructor, but for security reasons, a `\LogicException` will be thrown if you try to call the `addMap()` method again.

The methods `getMimeTypes()` and `getExtensions()` work the same as in the `Devanych\Mime\MimeTypes`, but the search is performed only in the preset mime types and file extensions that were passed to the constructor when creating an instance of the `Devanych\Mime\MimeTypesAllowed` class.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

Established project with proven stability

 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

Every ~62 days

Recently: every ~81 days

Total

8

Last Release

1983d ago

Major Versions

v1.1.2 → 2.0.02020-07-23

PHP version history (3 changes)v1.0.0PHP &gt;=7.2

2.0.0PHP &gt;=7.4

2.1.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7ab952aaa5ac8f82d6e96ef74c2f69082674a97eb3bc62f9d96c7304b2b4b082?d=identicon)[devanych](/maintainers/devanych)

---

Top Contributors

[![devanych](https://avatars.githubusercontent.com/u/20116244?v=4)](https://github.com/devanych "devanych (35 commits)")

---

Tags

mimemime-typemime-typesmimetypemimetypesphpphpmimemime-typemimetypemimetypesmime-types

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/devanych-mime-types/health.svg)

```
[![Health](https://phpackages.com/badges/devanych-mime-types/health.svg)](https://phpackages.com/packages/devanych-mime-types)
```

###  Alternatives

[symfony/mime

Allows manipulating MIME messages

2.8k668.8M911](/packages/symfony-mime)[dflydev/apache-mime-types

Apache MIME Types

701.9M35](/packages/dflydev-apache-mime-types)[fileeye/mimemap

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

259.2M9](/packages/fileeye-mimemap)[rosell-dk/image-mime-type-guesser

Guess mime type of images

108.0M5](/packages/rosell-dk-image-mime-type-guesser)[skyzyx/mimetypes

Creates a JSON document containing a thorough list of file extensions =&gt; mime types as provided by the Apache httpd project.

17202.4k5](/packages/skyzyx-mimetypes)

PHPackages © 2026

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