PHPackages                             karwana/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. karwana/mime

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

karwana/mime
============

1.0.0(11y ago)930.8k↓43.5%2MITPHPPHP &gt;=5.3.0

Since Jul 17Pushed 11y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (2)Used By (0)

MIME
====

[](#mime)

[![Build Status](https://camo.githubusercontent.com/9ec57bc153ccc43e526955712e2cf7ca530900755b138e1718a98fc0f510cc3f/68747470733a2f2f7472617669732d63692e6f72672f6b617277616e612f7068702d6d696d652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/karwana/php-mime)

MIME type and file extension utilities for PHP. Powered by [`finfo`](http://php.net/manual/en/book.fileinfo.php) and the Apache-provided public domain [mime.types](https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types) map of media types to unique file extension(s).

Examples
--------

[](#examples)

To get started, use the namespace wherever you want to use this library.

```
use Karwana\Mime;
```

### For uploaded files

[](#for-uploaded-files)

First we get the canonical extension and use it for the permanent file name. The original file name is used before falling back to running `finfo` if the file has no extension or if the extension is unlisted.

```
$extension = Mime::guessExtension($_FILES['my_file']['tmp_name'], $_FILES['my_file']['name']);

move_uploaded_file($_FILES['my_file']['tmp_name'], 'uploads/' . Uuid::v4() . '.' . $extension);
```

Later on, if we want to serve the file to the client, we can return the appropriate MIME type.

```
header('Content-Type: ' . Mime::guessType($my_file));
header('Content-Length: ' . filesize($my_file));
readfile($my_file);
```

### Add an extension to an extensionless file

[](#add-an-extension-to-an-extensionless-file)

You might want to do this as part of a batch job.

```
$my_file = 'path/to/extensionless_file';

rename($my_file, $my_file . '.' . Mime::guessExtension($my_file));
```

Development
-----------

[](#development)

Run tests using `$ vendor/bin/phing test`.

Use the provided script to update the MIME type list to the latest version from Apache's tracker.

```
curl https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types | \
bin/mime_types2json > Mime/Resources/mime_types.json
```

License
-------

[](#license)

See `LICENSE`.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

4324d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c824824c0f6b7d04d21b59c09b3ab7a55eed8191ed9bfe5d8854d6f624f94814?d=identicon)[mattcg](/maintainers/mattcg)

---

Top Contributors

[![mattcg](https://avatars.githubusercontent.com/u/282964?v=4)](https://github.com/mattcg "mattcg (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/tax-calculator

A set of interfaces and methods to clean up your application's tax calculations

8036.2k](/packages/spatie-tax-calculator)

PHPackages © 2026

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