PHPackages                             league/mime-type-detection - 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. league/mime-type-detection

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

league/mime-type-detection
==========================

Mime-type detection for Flysystem

1.16.0(1y ago)1.3k504.1M↓10.1%29[2 issues](https://github.com/thephpleague/mime-type-detection/issues)[5 PRs](https://github.com/thephpleague/mime-type-detection/pulls)20MITPHPPHP ^7.4 || ^8.0CI passing

Since Feb 28Pushed 1y ago8 watchersCompare

[ Source](https://github.com/thephpleague/mime-type-detection)[ Packagist](https://packagist.org/packages/league/mime-type-detection)[ GitHub Sponsors](https://github.com/frankdejonge)[ Fund](https://tidelift.com/funding/github/packagist/league/flysystem)[ RSS](/packages/league-mime-type-detection/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (20)Used By (20)

League Mime Type Detection
--------------------------

[](#league-mime-type-detection)

[![Author](https://camo.githubusercontent.com/d7d52362024683450617985055436a3ef44d3c2209c7ace3efdbdcd91f8324e4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406672616e6b64656a6f6e67652d626c75652e737667)](https://twitter.com/frankdejonge)[![Source Code](https://camo.githubusercontent.com/38bfe942fee9d07b2db4b3cefaaa6e27dae0ea7bfdf9a6aa17b63d1141e8bfa3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6c65616775652532466d696d652d2d747970652d2d646574656374696f6e2d626c75652e737667)](https://github.com/thephpleague/mime-type-detection)[![Latest Version](https://camo.githubusercontent.com/d25c6b8645d2e9e78d78a63c69b27b828e9bf126b8f07b66b9d21971013ae887/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f7468657068706c65616775652f6d696d652d747970652d646574656374696f6e2e737667)](https://github.com/thephpleague/mime-type-detection/releases)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](https://github.com/thephpleague/mime-type-detection/blob/master/LICENSE)[![Build Status](https://camo.githubusercontent.com/a75acbdbda05c096bff66ac3ea3022a059b97d34008d6167da07f0fee916aa0e/68747470733a2f2f7472617669732d63692e636f6d2f7468657068706c65616775652f6d696d652d747970652d646574656374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/thephpleague/mime-type-detection)[![Coverage Status](https://camo.githubusercontent.com/792e8bf24debe963a58e3da8e4fd076062f1caeb7e97b51ccbaa69505b1550a4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7468657068706c65616775652f6d696d652d747970652d646574656374696f6e2e737667)](https://scrutinizer-ci.com/g/thephpleague/mime-type-detection/code-structure)[![Quality Score](https://camo.githubusercontent.com/a6d2ffc0511ffc146cb4d51206ce6daf7a238e347db983ec627c1c49c5fd63e8/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7468657068706c65616775652f6d696d652d747970652d646574656374696f6e2e737667)](https://scrutinizer-ci.com/g/thephpleague/mime-type-detection)[![Total Downloads](https://camo.githubusercontent.com/37788ff34cf96003a4decc7a45c8905825a823c8f9a26ab8ed800b2d75db1990/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65616775652f6d696d652d747970652d646574656374696f6e2e737667)](https://packagist.org/packages/league/mime-type-detection)[![php 7.2+](https://camo.githubusercontent.com/2376755214318dbed6b54c54d063cd49a92f9116f93a173fca1952d529376fd6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d6d696e253230372e322d7265642e737667)](https://camo.githubusercontent.com/2376755214318dbed6b54c54d063cd49a92f9116f93a173fca1952d529376fd6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d6d696e253230372e322d7265642e737667)

This package supplies a generic mime-type detection interface with a `finfo` based implementation.

Usage
-----

[](#usage)

```
composer require league/mime-type-detection
```

Consumer interface
------------------

[](#consumer-interface)

Your code is advised to couple to the following interfaces:

- `League\MimetypeDetection\MimeTypeDetector`
    This contract is used to detect mimetypes based on file names and file contents.
- `League\MimetypeDetection\ExtensionLookup`
    This contract is used to lookup one or all mimetypes for a given file extension. Added in `1.13.0`.

### Detectors

[](#detectors)

Finfo with extension fallback:

```
$detector = new League\MimeTypeDetection\FinfoMimeTypeDetector();

// Detect by contents, fall back to detection by extension.
$mimeType = $detector->detectMimeType('some/path.php', 'string contents');

// Detect by contents only, no extension fallback.
$mimeType = $detector->detectMimeTypeFromBuffer('string contents');

// Detect by actual file, no extension fallback.
$mimeType = $detector->detectMimeTypeFromFile('existing/path.php');

// Only detect by extension
$mimeType = $detector->detectMimeTypeFromPath('any/path.php');

// Constructor options
$detector = new League\MimeTypeDetection\FinfoMimeTypeDetector(
  $pathToMimeDatabase, // Custom mime database location, default: ''
  $customExtensionMap, // Custom extension fallback mapp, default: null
  $bufferSampleSize // Buffer size limit, used to take a sample (substr) from the input buffer to reduce memory consumption.
);
```

Extension only:

```
$detector = new League\MimeTypeDetection\ExtensionMimeTypeDetector();

// Only detect by extension, ignores the file contents
$mimeType = $detector->detectMimeType('some/path.php', 'string contents');

// Always returns null
$mimeType = $detector->detectMimeTypeFromBuffer('string contents');

// Only detect by extension
$mimeType = $detector->detectMimeTypeFromFile('existing/path.php');

// Only detect by extension
$mimeType = $detector->detectMimeTypeFromPath('any/path.php');
```

Extension lookup by mime-type
-----------------------------

[](#extension-lookup-by-mime-type)

> This feature was added in version `1.13.0`

The various implementations can look up the extensions that can be used for a given mime-type.

```
// string | null
$extension = $detector->lookupExtension($mime$type);

// array
$allExtensions = $detector->lookupAllExtensions($mimeType);

```

Extension mime-type lookup
--------------------------

[](#extension-mime-type-lookup)

As a fallback for `finfo` based lookup, an extension map is used to determine the mime-type. There is an advised implementation shipped, which is generated from information collected by the npm package [mime-db](https://www.npmjs.com/package/mime-db).

### Provided extension maps

[](#provided-extension-maps)

Generated:

```
$map = new League\MimeTypeDetection\GeneratedExtensionToMimeTypeMap();

// string mime-type or NULL
$mimeType = $map->lookupMimeType('png');
```

Overriding decorator

```
$innerMap = new League\MimeTypeDetection\GeneratedExtensionToMimeTypeMap();
$map = new League\MimeTypeDetection\OverridingExtensionToMimeTypeMap($innerMap, ['png' => 'custom/mimetype']);

// string "custom/mimetype"
$mimeType = $map->lookupMimeType('png');
```

Empty:

```
$map = new League\MimeTypeDetection\EmptyExtensionToMimeTypeMap();

// Always returns NULL
$mimeType = $map->lookupMimeType('png');
```

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity79

Solid adoption and visibility

Community43

Growing community involvement

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 79.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 ~98 days

Recently: every ~104 days

Total

18

Last Release

626d ago

PHP version history (3 changes)1.0.0PHP ^7.2

1.4.0PHP ^7.2 || ^8.0

1.13.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/534693?v=4)[Frank de Jonge](/maintainers/frankdejonge)[@frankdejonge](https://github.com/frankdejonge)

---

Top Contributors

[![frankdejonge](https://avatars.githubusercontent.com/u/534693?v=4)](https://github.com/frankdejonge "frankdejonge (107 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (4 commits)")[![Awilum](https://avatars.githubusercontent.com/u/477114?v=4)](https://github.com/Awilum "Awilum (4 commits)")[![cancan101](https://avatars.githubusercontent.com/u/51059?v=4)](https://github.com/cancan101 "cancan101 (4 commits)")[![villfa](https://avatars.githubusercontent.com/u/2891564?v=4)](https://github.com/villfa "villfa (2 commits)")[![phil-davis](https://avatars.githubusercontent.com/u/1535615?v=4)](https://github.com/phil-davis "phil-davis (2 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (2 commits)")[![rgson](https://avatars.githubusercontent.com/u/4405148?v=4)](https://github.com/rgson "rgson (2 commits)")[![RouatbiH](https://avatars.githubusercontent.com/u/23016064?v=4)](https://github.com/RouatbiH "RouatbiH (2 commits)")[![maglnet](https://avatars.githubusercontent.com/u/4430279?v=4)](https://github.com/maglnet "maglnet (2 commits)")[![kguiougou-datasolution](https://avatars.githubusercontent.com/u/163284309?v=4)](https://github.com/kguiougou-datasolution "kguiougou-datasolution (1 commits)")[![Lctrs](https://avatars.githubusercontent.com/u/5477973?v=4)](https://github.com/Lctrs "Lctrs (1 commits)")[![alex-dna](https://avatars.githubusercontent.com/u/6982515?v=4)](https://github.com/alex-dna "alex-dna (1 commits)")[![Slamdunk](https://avatars.githubusercontent.com/u/152236?v=4)](https://github.com/Slamdunk "Slamdunk (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/league-mime-type-detection/health.svg)

```
[![Health](https://phpackages.com/badges/league-mime-type-detection/health.svg)](https://phpackages.com/packages/league-mime-type-detection)
```

PHPackages © 2026

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