PHPackages                             bayfrontmedia/php-mime-types - 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. bayfrontmedia/php-mime-types

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

bayfrontmedia/php-mime-types
============================

Simple class used to detect the appropriate MIME type of a file based on it's extension.

v2.1.0(5mo ago)474.0k↓14.6%12MITPHPPHP ^8.0

Since Jul 27Pushed 5mo agoCompare

[ Source](https://github.com/bayfrontmedia/php-mime-types)[ Packagist](https://packagist.org/packages/bayfrontmedia/php-mime-types)[ Docs](https://github.com/bayfrontmedia/php-mime-types)[ RSS](/packages/bayfrontmedia-php-mime-types/feed)WikiDiscussions master Synced 1w ago

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

PHP MIME types
--------------

[](#php-mime-types)

Simple class used to detect appropriate MIME type.

This is by no means meant to handle an exhaustive list of every single MIME type, but rather focuses on the [most common MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) used.

Since MIME types will be detected using the file extension, some file extension related methods are available to use as well.

- [License](#license)
- [Author](#author)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

License
-------

[](#license)

This project is open source and available under the [MIT License](LICENSE).

Author
------

[](#author)

[![Bayfront Media](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)

- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github&utm_medium=direct)
- [Bayfront Media GitHub](https://github.com/bayfrontmedia)

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

[](#requirements)

- PHP `^8.0` (Tested up to `8.4`)

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

[](#installation)

```
composer require bayfrontmedia/php-mime-types

```

Usage
-----

[](#usage)

- [getMimeTypes](#getmimetypes)
- [addMimeType](#addmimetype)
- [getExtension](#getextension)
- [hasExtension](#hasextension)
- [fromExtension](#fromextension)
- [fromFile](#fromfile)

---

### getMimeTypes

[](#getmimetypes)

**Description:**

Return array of all MIME types.

**Parameters:**

- None

**Returns:**

- (array)

**Example:**

```
use Bayfront\MimeTypes\MimeType;

print_r(MimeType::getMimeTypes());

```

---

### addMimeType

[](#addmimetype)

**Description:**

Adds new MIME type definitions.

**Parameters:**

- `$types` (array): Array whose keys are the file extension and values are the MIME type string

**Returns:**

- (void)

**Example:**

```
use Bayfront\MimeTypes\MimeType;

MimeType::addMimeType([
    'acgi' => 'text/html',
    'avs' => 'video/avs-video'
]);

```

---

### getExtension

[](#getextension)

**Description:**

Return extension of a given file, or empty string if not existing.

**Parameters:**

- `$file` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\MimeTypes\MimeType;

echo MimeType::getExtension('pretty-photo.jpg');

```

---

### hasExtension

[](#hasextension)

**Description:**

Checks if a file has a given extension.

**Parameters:**

- `$extension` (string)
- `$file` (string)

#### Returns:

[](#returns)

- (bool)

**Example:**

```
use Bayfront\MimeTypes\MimeType;

if (MimeType::hasExtension('jpg', 'pretty-photo.jpg') {
    // Do something
}

```

---

### fromExtension

[](#fromextension)

**Description:**

Get MIME type from file extension.

**Parameters:**

- `$extension` (string)
- `$default = 'application/octet-stream'` (string): Default MIME type to return if none found for given extension

**Returns:**

- (string)

**Example:**

```
use Bayfront\MimeTypes\MimeType;

echo MimeType::fromExtension('jpg');

```

---

### fromFile

[](#fromfile)

**Description:**

Get MIME type from file name.

**Parameters:**

- `$file` (string)
- `$default = 'application/octet-stream'` (string): Default MIME type to return if none found for given extension

**Returns:**

- (string)

**Example:**

```
use Bayfront\MimeTypes\MimeType;

echo MimeType::fromFile('pretty-photo.jpg');

```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance70

Regular maintenance activity

Popularity36

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

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

Total

5

Last Release

170d ago

Major Versions

v1.1.0 → v2.0.02023-01-26

PHP version history (2 changes)1.0.0PHP &gt;=7.1.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad62c8d0e69358fd63b16fdaa71d5359231cd0cf660bbc3419071dc705c63a8?d=identicon)[bayfrontmedia](/maintainers/bayfrontmedia)

---

Top Contributors

[![robinsonjohn](https://avatars.githubusercontent.com/u/24327848?v=4)](https://github.com/robinsonjohn "robinsonjohn (11 commits)")

---

Tags

extensionfilemimephptypephptypemimefileextension

### Embed Badge

![Health badge](/badges/bayfrontmedia-php-mime-types/health.svg)

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

###  Alternatives

[php-mime-mail-parser/php-mime-mail-parser

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

99110.1M35](/packages/php-mime-mail-parser-php-mime-mail-parser)[xobotyi/php-mime-type

A comprehensive MIME-types lib for PHP.

317.2k](/packages/xobotyi-php-mime-type)[dflydev/canal

Content analysis for the purpose of determining Internet media types.

35122.9k2](/packages/dflydev-canal)

PHPackages © 2026

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