PHPackages                             wwaz/mimetype-php - 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. wwaz/mimetype-php

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

wwaz/mimetype-php
=================

Determines mimetype of a filepath (string) or file resource

1.1.0(1y ago)042MITPHP

Since Aug 8Pushed 1mo ago1 watchersCompare

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

READMEChangelog (4)Dependencies (2)Versions (3)Used By (0)

mimetype-php
============

[](#mimetype-php)

Zero-config MIME type detection for PHP – automatically via file extension or content type.

[![PHP](https://camo.githubusercontent.com/f575af1b648be492e22e809caebece8d6ae4d5319ad769664ee7a52e1c31c939/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e302d626c7565)](https://php.net)

---

Quick Start
-----------

[](#quick-start)

```
composer require wwaz/mimetype
```

```
use wwaz\Mimetype\Mimetype;

echo Mimetype::get('document.pdf');  // → application/pdf
```

`get()` first tries detection by file extension. If that fails (missing extension or unknown type), it automatically falls back to content-type analysis – no configuration needed.

---

API
---

[](#api)

### `Mimetype::get(string $filename): string|false`

[](#mimetypegetstring-filename-stringfalse)

Universal method – the right choice for most cases.

```
Mimetype::get('image.png');           // → image/png
Mimetype::get('/var/upload/avatar');  // → image/jpeg  (via content type)
Mimetype::get('archive.tar.gz');      // → application/gzip
```

### `Mimetype::fromPath(string $filename): string|false`

[](#mimetypefrompathstring-filename-stringfalse)

Detection **by file extension only**. Throws `MimetypeException` if the extension is missing.

### `Mimetype::fromContentType(string $filename): string|false`

[](#mimetypefromcontenttypestring-filename-stringfalse)

Detection **by PHP `mime_content_type()` only**. The file must exist on the filesystem.

---

Examples
--------

[](#examples)

### 1 – Validate a file upload

[](#1--validate-a-file-upload)

```
$mime = Mimetype::get($_FILES['upload']['tmp_name']);

$allowed = ['image/jpeg', 'image/png', 'image/webp'];

if (!in_array($mime, $allowed)) {
    throw new RuntimeException('Only JPEG, PNG and WebP are allowed.');
}
```

### 2 – Set the Content-Type header

[](#2--set-the-content-type-header)

```
$file = '/var/www/assets/logo.svg';
header('Content-Type: ' . Mimetype::get($file));
readfile($file);
```

### 3 – Handle a missing extension gracefully

[](#3--handle-a-missing-extension-gracefully)

```
use wwaz\Mimetype\Exceptions\MimetypeException;

try {
    $mime = Mimetype::fromPath('mysterious-file');
} catch (MimetypeException $e) {
    // Fall back to content-type detection
    $mime = Mimetype::fromContentType('/path/to/mysterious-file');
}
```

---

Dependencies
------------

[](#dependencies)

PackagePurpose[ralouphie/mimey](https://github.com/ralouphie/mimey)Extensible MIME type databasePHP ≥ 8.0`string---

MIT © wwaz

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance67

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

Total

2

Last Release

507d ago

Major Versions

0.1.0 → 1.1.02025-02-12

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25566288?v=4)[WWAZ](/maintainers/WWAZ)[@WWAZ](https://github.com/WWAZ)

---

Top Contributors

[![WWAZ](https://avatars.githubusercontent.com/u/25566288?v=4)](https://github.com/WWAZ "WWAZ (10 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wwaz-mimetype-php/health.svg)

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

###  Alternatives

[customgento/configurable-tier-prices

Tier Prices For Configurable Products for Magento 1 changes the way Magento calculates tier prices of configurable products.

405.2k](/packages/customgento-configurable-tier-prices)

PHPackages © 2026

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