PHPackages                             wgenial/php-mimetyper - 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. wgenial/php-mimetyper

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

wgenial/php-mimetyper
=====================

PHP mime type and extension mapping library: compatible with Symfony, powered by jshttp/mime-db

2.0.0(5y ago)22.5k1MITPHP

Since Sep 12Pushed 5y agoCompare

[ Source](https://github.com/wgenial/php-mimetyper)[ Packagist](https://packagist.org/packages/wgenial/php-mimetyper)[ RSS](/packages/wgenial-php-mimetyper/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (7)Used By (1)

php-mimetyper
=============

[](#php-mimetyper)

PHP mime type and extension mapping library: built with [jshttp/mime-db](http://github.com/jshttp/mime-db).

[![Packagist](https://camo.githubusercontent.com/ba932c235e023072c44bdc9aa28fd5617a9b9bed83de2d0290ef12f41c7af982/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7767656e69616c2f7068702d6d696d6574797065722e7376673f6d61784167653d393030)](https://packagist.org/packages/wgenial/php-mimetyper)[![GitHub license](https://camo.githubusercontent.com/a16f6871438665f6cf1877ddf9b1be7e07204dc889901f3373f05f411415d133/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7767656e69616c2f7068702d6d696d6574797065722e737667)](https://github.com/wgenial/php-mimetyper/blob/master/LICENSE)

```
use MimeTyper\Repository\MimeDbRepository;

$mimeRepository = new MimeDbRepository();

$mimeRepository->findExtensions("image/jpeg"); // ["jpeg","jpg","jpe"]
$mimeRepository->findExtension("image/jpeg"); // "jpeg"

$mimeRepository->findType("html"); // "html"
$mimeRepository->findType("js"); // 'application/javascript'
```

> The most complete and up-to-date mime type mapping for PHP!

The goal is to provide a complete and up-to-date mime types mapping for PHP and build a comprehensive and simple interface for PHP.

This package is heavily inspired from [dflydev/dflydev-apache-mime-types](https://github.com/dflydev/dflydev-apache-mime-types) and [adrienrn/php-mimetyper](https://github.com/adrienrn/php-mimetyper) work and extends it.

Mime types mapping, the right way.
----------------------------------

[](#mime-types-mapping-the-right-way)

This library uses [jshttp/mime-db](http://github.com/jshttp/mime-db) as its default mapping which aggregates data from multiple sources and creates a single `db.json` making it the most complete two ways mapping, from mime to extension and extension to mime types too.

- [IANA](http://www.iana.org/assignments/media-types/media-types.xhtml)
- [Apache](http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types)
- [Nginx](http://hg.nginx.org/nginx/file/tip/conf/mime.types)
- Some (very) useful custom aliases;

Custom mime types and custom repositories
-----------------------------------------

[](#custom-mime-types-and-custom-repositories)

Some custom types (aliases really) are maintained locally too, in the same JSON format as jshttp/mime-db.

```
use MimeTyper\Repository\ExtendedRepository;

$mimeRepostory = new ExtendedRepository();

$mimeRepository->findExtensions("text/x-php"); // ["php", "php2", "php3", "php4", "php5"]

$mimeRepository->findTypes("php"); // ["text/x-php", "application/x-php", "text/php", "application/php", "application/x-httpd-php"]
$mimeRepository->findType("php"); // "text/x-php"
```

The reason to maintain aliases locally helps with overall compatibility between mime type guessing methods. Tools detecting mime types don't always return standard mime type or the standard mime type does not exist. All of those custom mime types might be [added to jshttp/mime-db custom types in the end](https://github.com/jshttp/mime-db/issues/49).

**Example:** Debian will detect a PHP file as `text/x-php` while browsers will send `application/x-httpd-php`. It goes the same with files such as Javascript (`application/javascript` vs `text/javascript`) or Microsoft Office / Libre Office files.

Don't hesitate to make a pull request to discuss this.

Mime types for Symfony and Laravel
----------------------------------

[](#mime-types-for-symfony-and-laravel)

This library is compatible with your Symfony or Laravel app to enjoy the completeness of the mapping.

Use the `ExtraMimeTypeExtensionGuesser` as a bridge class between Symfony `ExtensionGuesser` and this package `RepositoryInterface`.

```
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;

use MimeTyper\Repository\ExtendedRepository;
use MimeTyper\Symfony\ExtraMimeTypeExtensionGuesser;

$symfonyGuesser = ExtensionGuesser::getInstance();
$extraGuesser = new ExtraMimeTypeExtensionGuesser(
    new ExtendedRepository()
);
$symfonyGuesser->register($extraGuesser);
```

This example uses the `ExtendedRepository` (mime-db and local custom mime types), you can use the default `MimeDbRepository`, implement your own or use a `CompositeRepository` to aggregate multiple repostories.

Safe detection of mime type in PHP
----------------------------------

[](#safe-detection-of-mime-type-in-php)

Before mapping type to extension or extension to type, you need to be able to properly detect the mime type of a file.

For security reasons, **do not trust browsers**, eg `$_FILES['your_file']['type']`, when it comes to detect the mime type of a file.

To safely detect the mime type of a file, . Symfony is giving a great example with their MimeTypeGuesser implementation of:

- [FileinfoMimeTypeGuesser](https://github.com/symfony/http-foundation/blob/3.1/File/MimeType/FileinfoMimeTypeGuesser.php)
- [FileBinaryMimeTypeGuesser](https://github.com/symfony/http-foundation/blob/3.1/File/MimeType/FileBinaryMimeTypeGuesser.php)

It all ends up inspecting the file using [finfo](http://php.net/manual/en/function.finfo-open.php) and relies on magic db files. PHP will use its own magic db or your system magic db depending on your environement.

Other PHP libraries for mime types
----------------------------------

[](#other-php-libraries-for-mime-types)

- [dflydev/dflydev-apache-mime-types](https://github.com/dflydev/dflydev-apache-mime-types)

    Uses `mime.types` Apache file, comprehensive api. As stated before, php-mimetyper is heavily inspired by this, extending it to be a bit more complete using an external mapping and a wider interface.
- [symfony/http-foundation](https://github.com/symfony/http-foundation/tree/master/File/MimeType)

    Symfony provides a nice interface for guessing mime types and extensions but uses only a local mapping based on Apache registry, see above to bridge it to this package.
- [davidpersson/mm](https://github.com/davidpersson/mm)

    Library for media processing and mime type and extension guessing. Uses FreeDesktop magic.db file for the latter.
- [Hoa/Mime](https://github.com/hoaproject/Mime)

    The Hoa package to deal with mime types. Uses `mime.types` Apache file (local fallback) and relies on static methods.
- [karwana/php-mime](https://github.com/karwana/php-mime)

    Uses `mime.types` Apache file and finfo, requires PHP &gt;=5.4.
- [PEAR/MIME\_Type](https://github.com/pear/MIME_Type)

    Detect the mime type of a file: uses internally finfo\_file, mime\_content\_type or file command to guess the mime type.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 72.5% 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 ~352 days

Total

5

Last Release

2117d ago

Major Versions

0.2.1 → 1.0.02018-11-05

1.0.0 → 2.0.02020-07-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/06e2cd462dd312f4bacea716be1d9a414e66b31199b2a387a895cb9bc6b480a5?d=identicon)[giovanigenerali](/maintainers/giovanigenerali)

---

Top Contributors

[![adrienrn](https://avatars.githubusercontent.com/u/5598481?v=4)](https://github.com/adrienrn "adrienrn (29 commits)")[![giovanigenerali](https://avatars.githubusercontent.com/u/41435?v=4)](https://github.com/giovanigenerali "giovanigenerali (10 commits)")[![reshadman](https://avatars.githubusercontent.com/u/5187816?v=4)](https://github.com/reshadman "reshadman (1 commits)")

---

Tags

mimemime-databasemime-parsermime-typemime-typesmimetype

### Embed Badge

![Health badge](/badges/wgenial-php-mimetyper/health.svg)

```
[![Health](https://phpackages.com/badges/wgenial-php-mimetyper/health.svg)](https://phpackages.com/packages/wgenial-php-mimetyper)
```

###  Alternatives

[sculpin/sculpin

Static Site Generator

1.5k102.8k12](/packages/sculpin-sculpin)[php-junior/laravel-video-chat

Laravel Video Chat using Socket.IO and WebRTC

82018.1k](/packages/php-junior-laravel-video-chat)[klepak/nova-dynamic-page-title

Dynamically updates Laravel Nova page title based on data from Vue router.

11154.8k](/packages/klepak-nova-dynamic-page-title)

PHPackages © 2026

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