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

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

alembic/mime
============

Just a port of npm's mime package

v1.0.4(10y ago)271MITPHP

Since Jul 19Pushed 10y ago1 watchersCompare

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

READMEChangelog (5)DependenciesVersions (6)Used By (0)

PHP-Mime
========

[](#php-mime)

[![SensioLabsInsight](https://camo.githubusercontent.com/22a9a0c1a97157052c87ee04a79738e3fd519ccd724cec609ee0d8a083d5cdf7/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f65393130333635342d383435662d343062372d386565622d3030396534396530393036372e7376673f7374796c653d666c61742d737175617265266c6162656c3d696e7369676874)](https://insight.sensiolabs.com/projects/e9103654-845f-40b7-8eeb-009e49e09067)[![Packagist (Composer)](https://camo.githubusercontent.com/fbf7e5fc382efb34588f6b62be36600bc28f2c54ce2285749fd4a55f36ed4f56/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c656d6269632f6d696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alembic/mime)[![MIT License](https://camo.githubusercontent.com/5f7a8cb3ff1e5bcd058569ef1f79aab8debf443b823eb82e43798522bec6b767/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616c656d6269632f6d696d652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/5f7a8cb3ff1e5bcd058569ef1f79aab8debf443b823eb82e43798522bec6b767/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616c656d6269632f6d696d652e7376673f7374796c653d666c61742d737175617265)

Comprehensive MIME type mapping API, PHP clone of [broofa/node-mime](https://github.com/broofa/node-mime). MIME database from [jshttp/mime-db](https://github.com/jshttp/mime-db).

Data sources
------------

[](#data-sources)

This library uses the mime-db repository. The updates are automatically pulled from their repository, using `bin/pull-mime-db.php [out] [--with-apache]`.

By default this library exposes merged nginx + mime-db "custom types" (**119** usable mimes) and extensions. Those are the most commons types of the Internet. The library also includes the Apache types. A lot of Apache types are, in most part, useless and they are very numerous (**884** usable mimes), so, in order to reduce the memory footprint, Apache types are not loaded by default.

If you're searching for a library with more options and features, check [hoaproject/Mime](https://github.com/hoaproject/Mime). If you need something simple, this library is for you ! For example, this library is perfect to implement a HTTP server that serves static files with a mime type based on the extension - since MIME scanning is too slow.

Install &amp; Usage
-------------------

[](#install--usage)

```
composer require alembic/mime

```

```
use Alembic\Mime\Mime;
```

**Note:** All the methods exposed below can be called statically or with an instance of the `Mime` class (more practical in DI environments). Please note that, even when using instance calls, the MIMEs database is shared because it is static.

API — Queries
-------------

[](#api--queries)

### Mime::lookup($path \[, $fallback\])

[](#mimelookuppath--fallback)

Get the mime type associated with a file, if no mime type is found `$fallback` (`Mime::$defaultType` by default, which is `application/octet-stream`) is returned. Performs a case-insensitive lookup using the extension in `$path` (the substring after the last '.'). E.g.

```
use Alembic\Mime\Mime;

Mime::lookup('/path/to/file.txt');         # => 'text/plain'
Mime::lookup('file.txt');                  # => 'text/plain'
Mime::lookup('.TXT');                      # => 'text/plain'
Mime::lookup('htm');                       # => 'text/html'
Mime::lookup('unknown');                   # => 'application/octet-stream'
Mime::lookup('unknown', null);             # => null
# Instance mode:
(new Mime)->lookup('folder/file');         # => 'application/octet-stream'
```

### Mime::$defaultType

[](#mimedefaulttype)

The mime type returned when `Mime::lookup` fails to find the extension searched for (default is the standard `application/octet-stream`).

### Mime::extension($type)

[](#mimeextensiontype)

Get the preferred extension for `$type`.

```
Mime::extension('text/html');                 # => 'html'
Mime::extension('application/octet-stream');  # => 'bin'
```

### Mime::$defaultExtension

[](#mimedefaultextension)

The extension returned when `Mime::extension` fails to find the type searched for (**warning**, default is `null`).

API — Defining Types
--------------------

[](#api--defining-types)

Custom type mappings can be added on a per-project basis via the following APIs.

### Mime::define()

[](#mimedefine)

Add custom mime/extension mappings.

```
Mime::define([
    'text/x-some-format'      => ['x-sf', 'x-sft', 'x-sfml'],
    'application/x-my-type'   => ['x-mt', 'x-mtt'],
    'application/x-my-format' => 'x-mf', # string allowed for unique ext
    # etc ...
]);

Mime::lookup('x-sft');  # => 'text/x-some-format'
```

As said before, the first entry in the extensions array is returned by `Mime::extension()`. E.g.

```
Mime::extension('text/x-some-format');  # => 'x-sf'
```

### Mime::load($filepath)

[](#mimeloadfilepath)

Load mappings from an Apache ".types" file or a Nginx file containing a `types` block. The format (Nginx or Apache) is automagically detected based on the content. Since the library uses `file_get_contents()`, the `$filepath` argument could be a filesystem path, an FTP path, an URL, whatever. If the file couldn't be loaded (wrong path or insufficient privileges), it throws a `\RuntimeException`.

```
Mime::load('./my_project.types');
```

The Apache .types file or the Nginx `types` block format is simple — see the [examples](/examples) directory for examples.

### Mime::apacheExtend()

[](#mimeapacheextend)

Loads the packaged database of merged mime-db+nginx+Apache MIME types and extensions. The basic database (mime-db+nginx) is loaded by default and weighs 8 KiB, when the all-in-one database loaded by this method weighs 70 KiB.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity67

Established project with proven stability

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

Total

5

Last Release

3678d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/434598cd8e66845191010e4bcb5db8e8278947458da045be5286020d8d97a581?d=identicon)[morgan-linux](/maintainers/morgan-linux)

---

Tags

mimemappingextension

### Embed Badge

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

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

###  Alternatives

[nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

87129.2k2](/packages/nterms-yii2-mailqueue)[xobotyi/php-mime-type

A comprehensive MIME-types lib for PHP.

317.2k](/packages/xobotyi-php-mime-type)[directmailteam/direct-mail

Advanced Direct Mail/Newsletter mailer system with sophisticated options for personalization of emails including response statistics.

39209.3k2](/packages/directmailteam-direct-mail)[silverstripe/mimevalidator

Checks uploaded file content roughly matches a known MIME type for the file extension.

102.0M9](/packages/silverstripe-mimevalidator)

PHPackages © 2026

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