PHPackages                             intervention/mimesniffer - 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. intervention/mimesniffer

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

intervention/mimesniffer
========================

PHP MIME Type Sniffer

2.1.0(1y ago)23370.3k↓32.2%4MITPHPPHP ^8.1CI passing

Since Jul 21Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/Intervention/mimesniffer)[ Packagist](https://packagist.org/packages/intervention/mimesniffer)[ Docs](http://intervention.io/)[ Fund](https://paypal.me/interventionio)[ GitHub Sponsors](https://github.com/Intervention)[ RSS](/packages/intervention-mimesniffer/feed)WikiDiscussions develop Synced 2w ago

READMEChangelogDependencies (4)Versions (20)Used By (0)

PHP Media type (MIME) detector
==============================

[](#php-media-type-mime-detector)

[![Latest Version](https://camo.githubusercontent.com/5b7fe75c49aefabc7951d766eab17d3e477e8bf205ec9599a742c1b4dec04d02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e74657276656e74696f6e2f6d696d65736e69666665722e737667)](https://packagist.org/packages/intervention/mimesniffer)[![Tests](https://github.com/Intervention/mimesniffer/actions/workflows/build.yml/badge.svg)](https://github.com/Intervention/mimesniffer/actions/workflows/build.yml)[![Monthly Downloads](https://camo.githubusercontent.com/50ca17fc02adbede3206b79d649f17ef3f3ca7ef4cf832d335ef36bf4e8541e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f696e74657276656e74696f6e2f6d696d65736e69666665722e737667)](https://packagist.org/packages/intervention/mimesniffer/stats)[![Support me on Ko-fi](https://raw.githubusercontent.com/Intervention/mimesniffer/main/.github/images/support.svg)](https://ko-fi.com/interventionphp)

Detecting MIME Content-type in PHP is easy with [mime\_content\_type](https://www.php.net/manual/en/function.mime-content-type.php)or [Fileinfo](https://www.php.net/manual/en/book.fileinfo.php). But Fileinfo as an extension is sometimes not available on the server. The function `mime_content_type` wants a path to the filesystem as argument and doesn't process if we only have a string value. This package makes it easy to detect the mime types of the content of a given file or string, without any extension dependencies.

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

[](#installation)

Install the package easily via composer:

```
composer require intervention/mimesniffer
```

Usage
-----

[](#usage)

Here are some code samples, to show how the library is handled.

```
use Intervention\MimeSniffer\MimeSniffer;
use Intervention\MimeSniffer\Types\ImageJpeg;

// universal factory method
$sniffer = MimeSniffer::create($content);

// or detect given string
$sniffer = MimeSniffer::createFromString($content);

// or detect given file
$sniffer = MimeSniffer::createFromFilename('image.jpg');

// or detect from file pointer
$sniffer = MimeSniffer::createFromFilename(fopen('test.jpg', 'r'));

// returns object of detected type
$type = $sniffer->getType();

$bool = $type->isBinary(); // check if we have binary data
$bool = $type->isImage(); // check if we are dealing with an image
$bool = $type->isVideo(); // check video data was detected
$bool = $type->isAudio(); // check if we have detected audio data
$bool = $type->isArchive(); // check if an archive was detected
$type = (string) $type; // cast type to string (e.g. "image/jpeg")

// you can also check, if the content matches a specific type
$bool = $sniffer->matches(new ImageJpeg);

// or check, if the content matches an array of types
$bool = $sniffer->matches([ImageJpeg::class, ImageGif::class]);

// or check, if the content matches an array of type objects
$bool = $sniffer->matches([new ImageJpeg, $type]);
```

If your prefer non-static initialization:

```
use Intervention\MimeSniffer\MimeSniffer;

// create instance with constructor
$sniffer = new MimeSniffer($content);

// with setter for given content
$type = $sniffer->setFromString($other_content)->getType();

// or with setter for filename
$type = $sniffer->setFromFilename('images/image.jpg')->getType();

// or with setter for file pointer
$type = $sniffer->setFromPointer(fopen('images/image.jpg', 'r'))->getType();
```

**Currently only the following file types can be detected. More will be added in a next release.**

### Images

[](#images)

- Image encoded as JPEG raw or in the JFIF or Exif file format
- Image file encoded in the Graphics Interchange Format (GIF)
- Image encoded in the Portable Network Graphics format (PNG)
- Image encoded as BMP file, a bitmap format
- Image encoded in High Efficiency Image File Format (HEIC/HEIF)
- Icon encoded in ICO file format
- Image in Google WebP image format
- Scalable Vector Graphics (SVG)
- Tagged Image File Format (TIFF)
- Image encoded Photoshop Document file format (PSD)
- AV1 Image File Format (AVIF)
- JPEG 2000 File Format

### Archives

[](#archives)

- GZIP compressed
- ZIP file
- RAR archive
- TAR file

### Videos

[](#videos)

- AVI
- MPEG-1 and MPEG-2 video
- MKV media container

### Audio

[](#audio)

- MP3 file
- FLAC file

### Other

[](#other)

- PDF document
- OGG media container
- SQLite Database
- application/octet-stream (default binary)
- text/plain (default)

Contributing
------------

[](#contributing)

Contributions are welcome. Please note the following guidelines before submiting your pull request.

- Follow [PSR-2](http://www.php-fig.org/psr/psr-2/) coding standards.
- Write tests for new functions and added features

Development &amp; Testing
-------------------------

[](#development--testing)

With this package comes a Docker image to build a test suite and analysis container. To build this container you have to have Docker installed on your system. You can run all tests with this command.

```
docker-compose run --rm --build tests
```

Run the static analyzer on the code base.

```
docker-compose run --rm --build analysis
```

Authors
-------

[](#authors)

This library is developed and maintained by [Oliver Vogel](https://intervention.io)

License
-------

[](#license)

Intervention MimeSniffer is licensed under the [MIT License](LICENSE).

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance58

Moderate activity, may be stable

Popularity45

Moderate usage in the ecosystem

Community9

Small or concentrated contributor base

Maturity77

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 ~112 days

Recently: every ~92 days

Total

18

Last Release

680d ago

Major Versions

0.5.1 → 1.0.02023-10-27

1.0.1 → 2.0.02024-05-04

PHP version history (4 changes)0.2.0PHP ^7.0

0.4.0PHP ^7.2

0.4.1PHP ^7.3|^8.0

2.0.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![olivervogel](https://avatars.githubusercontent.com/u/884642?v=4)](https://github.com/olivervogel "olivervogel (107 commits)")

---

Tags

mimemime-parsermime-typestypemimedetectorsniffer

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/intervention-mimesniffer/health.svg)

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

###  Alternatives

[symfony/mime

Allows manipulating MIME messages

2.8k733.6M1.6k](/packages/symfony-mime)[zbateson/mail-mime-parser

MIME email message parser

55054.8M105](/packages/zbateson-mail-mime-parser)[php-mime-mail-parser/php-mime-mail-parser

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

1.0k10.6M39](/packages/php-mime-mail-parser-php-mime-mail-parser)[nette/mail

📧 Nette Mail: A handy library for creating and sending emails in PHP.

54110.3M291](/packages/nette-mail)[zbateson/stream-decorators

PHP psr7 stream decorators for mime message part streams

4754.1M11](/packages/zbateson-stream-decorators)[dflydev/apache-mime-types

Apache MIME Types

702.0M38](/packages/dflydev-apache-mime-types)

PHPackages © 2026

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