PHPackages                             josantonius/mimetype - 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. josantonius/mimetype

Abandoned → [josantonius/mime-type](/?search=josantonius%2Fmime-type)ArchivedLibrary[Mail &amp; Notifications](/categories/mail)

josantonius/mimetype
====================

PHP library to get MIME types from extensions.

v2.0.3(2y ago)914.9k↓33.3%7MITPHPPHP ^8.0

Since Jan 28Pushed 2y ago2 watchersCompare

[ Source](https://github.com/josantonius/php-mime-type)[ Packagist](https://packagist.org/packages/josantonius/mimetype)[ GitHub Sponsors](https://github.com/Josantonius)[ RSS](/packages/josantonius-mimetype/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (16)Used By (0)

PHP MimeType library
====================

[](#php-mimetype-library)

[![Latest Stable Version](https://camo.githubusercontent.com/49c6f5fa44f96e67450484a7d1096d24312e18aaeeb9191b1ade2fc2f008719e/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f6d696d652d747970652f762f737461626c65)](https://packagist.org/packages/josantonius/mime-type)[![License](https://camo.githubusercontent.com/ce89e6989e25a2fac4372d54413632cb3f5d3063a973726a35b29f0d6d71aa6e/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f6d696d652d747970652f6c6963656e7365)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/193a61c779d2cb2eb3535ba33eed56a51241acaa5828f623eac99ff3e7ea4990/68747470733a2f2f706f7365722e707567782e6f72672f6a6f73616e746f6e6975732f6d696d652d747970652f646f776e6c6f616473)](https://packagist.org/packages/josantonius/mime-type)[![CI](https://github.com/josantonius/php-mime-type/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/josantonius/php-mime-type/actions/workflows/ci.yml)[![CodeCov](https://camo.githubusercontent.com/b7b36081ed1df002cf0233fe1a793b13c78b4f8cffaa75baa05c59c88bbed20b/68747470733a2f2f636f6465636f762e696f2f67682f6a6f73616e746f6e6975732f7068702d6d696d652d747970652f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/josantonius/php-mime-type)[![PSR1](https://camo.githubusercontent.com/b502a899c9aec217e98971160f816f87346be272cf1a25cfa4793f2ee724bfc8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d312d6635373034362e737667)](https://www.php-fig.org/psr/psr-1/)[![PSR4](https://camo.githubusercontent.com/d1c090de87e968254a6658528f3bfe9c9dad422d6047fd1323dc211560182c01/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d342d3962353962362e737667)](https://www.php-fig.org/psr/psr-4/)[![PSR12](https://camo.githubusercontent.com/19c529c6dc0656dcc2a16c1a84af450b7bd0dc7b0571b8f17e4fc9f2414f8821/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d31322d3161626339632e737667)](https://www.php-fig.org/psr/psr-12/)

PHP library to get MIME types from extensions.

> The original concept of my project, linking a single mimetype to a file extension, has been found to be insufficient in accurately reflecting the many-to-one relationships that exist in real-world use-cases. In practice, multiple file extensions often correspond to a single mimetype, rendering my existing design approach suboptimal.

> Given these insights, I've decided to archive this repository. I recommend those interested to look at the approach taken by the repository [patrickmccallum/mimetype-io](https://github.com/patrickmccallum/mimetype-io/blob/master/src/mimeData.json). This project adopts a more nuanced perspective, effectively managing mimetypes by acknowledging the possibility of multiple extensions corresponding to a single mimetype. I believe this is a more promising approach for managing mimetypes moving forward.

Requirements
------------

[](#requirements)

- Operating System: Linux | Windows.
- PHP versions: 8.0 | 8.1 | 8.2.

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

[](#installation)

The preferred way to install this extension is through [Composer](http://getcomposer.org/download/).

To install **PHP MimeType library**, simply:

```
composer require josantonius/mime-type
```

The previous command will only install the necessary files, if you prefer to **download the entire source code** you can use:

```
composer require josantonius/mime-type --prefer-source
```

You can also **clone the complete repository** with Git:

```
git clone https://github.com/josantonius/php-mime-type.git
```

Available Classes
-----------------

[](#available-classes)

### MimeType

[](#mimetype)

`Josantonius\MimeType\MimeType`

Get array with all MIME types:

```
public function all(): array;
```

Get file extension from MIME type:

```
public function getExtension(string $mimeType): string|null;
```

Get MIME type from file extension:

```
public function getMime(string $extension): string|null;
```

### MimeTypeCollection

[](#mimetypecollection)

`Josantonius\MimeType\MimeTypeCollection`

Get array with all MIME types:

```
public static function all(): array;
```

Get file extension from MIME type:

```
public static function getExtension(string $mimeType): string|null;
```

Get MIME type from file extension:

```
public static function getMime(string $extension): string|null;
```

Usage
-----

[](#usage)

Example of use for this library:

### Get array with all MIME types

[](#get-array-with-all-mime-types)

```
use Josantonius\MimeType\MimeType;

$mimeType = new MimeType();

$mimeType->all();
```

```
use Josantonius\MimeType\MimeTypeCollection;

MimeTypeCollection::all();
```

Result:

```
[
    [".123"]=> "application/vnd.lotus-1-2-3"
    [".3dml"]=> "text/vnd.in3d.3dml"
    [".3g2"]=> "video/3gpp2"
    [".3gp"]=> "video/3gpp"
    [".7z"]=> "application/x-7z-compressed"
    [".aab"]=> "application/x-authorware-bin"
    [".aac"]=> "audio/x-aac"
    [".aam"]=> "application/x-authorware-map"
    [".aas"]=> "application/x-authorware-seg"
    [".abw"]=> "application/x-abiword"
    (...)
]
```

### Get file extension from MIME type

[](#get-file-extension-from-mime-type)

```
use Josantonius\MimeType\MimeType;

$mimeType = new MimeType();

$mimeType->getExtension('text/html'); // .html
```

```
use Josantonius\MimeType\MimeTypeCollection;

MimeTypeCollection::getExtension('application/zip'); // .zip
```

### Get MIME type from file extension

[](#get-mime-type-from-file-extension)

```
use Josantonius\MimeType\MimeType;

$mimeType = new MimeType();

$mimeType->getMime('.tar'); // application/x-tar

// The dot can be omitted:

$mimeType->getMime('mp4'); // video/mp4
```

```
use Josantonius\MimeType\MimeTypeCollection;

MimeTypeCollection::getMime('.json'); // application/json
```

Tests
-----

[](#tests)

To run [tests](tests) you just need [composer](http://getcomposer.org/download/)and to execute the following:

```
git clone https://github.com/josantonius/php-mime-type.git
```

```
cd PHP-MimeType
```

```
composer install
```

Run unit tests with [PHPUnit](https://phpunit.de/):

```
composer phpunit
```

Run code standard tests with [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer):

```
composer phpcs
```

Run [PHP Mess Detector](https://phpmd.org/) tests to detect inconsistencies in code style:

```
composer phpmd
```

Run all previous tests:

```
composer tests
```

TODO
----

[](#todo)

- Add new feature
- Improve tests
- Improve documentation
- Improve English translation in the README file
- Refactor code for disabled code style rules (see phpmd.xml and phpcs.xml)

Changelog
---------

[](#changelog)

Detailed changes for each release are documented in the [release notes](https://github.com/josantonius/php-mime-type/releases).

Contribution
------------

[](#contribution)

Please make sure to read the [Contributing Guide](.github/CONTRIBUTING.md), before making a pull request, start a discussion or report a issue.

Thanks to all [contributors](https://github.com/josantonius/php-mime-type/graphs/contributors)! ❤️

Sponsor
-------

[](#sponsor)

If this project helps you to reduce your development time, [you can sponsor me](https://github.com/josantonius#sponsor) to support my open source work 😊

License
-------

[](#license)

This repository is licensed under the [MIT License](LICENSE).

Copyright © 2016-2023, [Josantonius](https://github.com/josantonius#contact)

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 93.3% 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 ~196 days

Recently: every ~503 days

Total

13

Last Release

1034d ago

Major Versions

1.1.7 → v2.0.02022-08-02

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

1.1.0PHP &gt;=5.6

1.1.1PHP ^5.6 || ^7.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b221283501ec8a9cbaefaf27821a91ae8ddd33bddf1fccc6c6815b7ad216ff1?d=identicon)[Josantonius](/maintainers/Josantonius)

---

Top Contributors

[![josantonius](https://avatars.githubusercontent.com/u/18104336?v=4)](https://github.com/josantonius "josantonius (98 commits)")[![touchweb-vincent](https://avatars.githubusercontent.com/u/315173?v=4)](https://github.com/touchweb-vincent "touchweb-vincent (3 commits)")[![derrickobedgiu1](https://avatars.githubusercontent.com/u/122678727?v=4)](https://github.com/derrickobedgiu1 "derrickobedgiu1 (1 commits)")[![MASNathan](https://avatars.githubusercontent.com/u/2139464?v=4)](https://github.com/MASNathan "MASNathan (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![scicali](https://avatars.githubusercontent.com/u/62660196?v=4)](https://github.com/scicali "scicali (1 commits)")

---

Tags

composerheaders-mimemime-typemime-typesmimetypephpphpmimemime-typeaudiovideomultipartapplication

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/josantonius-mimetype/health.svg)

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

###  Alternatives

[symfony/mime

Allows manipulating MIME messages

2.8k668.8M911](/packages/symfony-mime)[php-mime-mail-parser/php-mime-mail-parser

A fully tested email parser for PHP 8.0+ (mailparse extension wrapper).

9979.6M27](/packages/php-mime-mail-parser-php-mime-mail-parser)[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)[vaibhavpandeyvpz/phemail

A pure PHP MIME parser for parsing raw email files (.eml) with full support for multipart messages, nested structures, and RFC 2046 compliance.

33121.7k1](/packages/vaibhavpandeyvpz-phemail)

PHPackages © 2026

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