PHPackages                             awaisjameel/mimetypes - 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. awaisjameel/mimetypes

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

awaisjameel/mimetypes
=====================

A Laravel package for dynamically fetching, caching, and resolving MIME types and file extensions using the latest Apache MIME types list. Perfect for file upload validation and content-type detection.

1.0.0(1y ago)047[4 PRs](https://github.com/awaisjameel/MimeTypes/pulls)1MITPHPPHP &gt;=7.4CI passing

Since Feb 3Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/awaisjameel/MimeTypes)[ Packagist](https://packagist.org/packages/awaisjameel/mimetypes)[ Docs](https://github.com/awaisjameel/mimetypes)[ GitHub Sponsors](https://github.com/AwaisJameel)[ RSS](/packages/awaisjameel-mimetypes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (13)Versions (6)Used By (1)

MimeTypes
=========

[](#mimetypes)

**MimeTypes** is a Laravel package designed to dynamically fetch, cache, and resolve MIME types and file extensions. It retrieves the latest MIME type mappings from the official [Apache MIME types repository](http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types) and provides an easy-to-use API for resolving MIME types from file extensions and vice versa.

With built-in caching support and seamless integration into Laravel's ecosystem, this package ensures optimal performance and up-to-date data for handling file types.

### Features

[](#features)

- **Dynamic MIME Type Fetching**: Automatically fetch the latest MIME types from Apache's repository.
- **Bi-Directional Resolution**: Resolve MIME types to extensions and extensions to MIME types.
- **Caching for Performance**: Cache MIME type mappings for a configurable duration (default: 24 hours).
- **Laravel Integration**: Fully compatible with Laravel, using its caching and HTTP systems.
- **Customizable TTL**: Configure cache expiration to suit your application's requirements.
- **Robust Error Handling**: Clear and descriptive exceptions for invalid inputs or network issues.

### Use Cases

[](#use-cases)

- **File Upload Validation** : Ensure files match the expected MIME type or extension before processing.
- **Content-Type Detection** : Dynamically determine the appropriate MIME type for file downloads or API responses.
- **Dynamic File Handling** : Manage and validate file operations based on the latest MIME standards.

### Why Use MimeTypes?

[](#why-use-mimetypes)

Dealing with MIME types can be cumbersome when relying on outdated static mappings or manually maintaining lists. **MimeTypes** automates the process, giving you:

- Up-to-date MIME mappings.
- Improved performance with caching.
- Simplicity with a Laravel-tailored API.

Whether you're working on file upload systems, API responses, or content-type validation, this package provides a reliable and efficient solution for managing MIME types.

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

[](#installation)

You can install the package via composer:

```
composer require awaisjameel/mimetypes
```

You can publish the config file with:

```
php artisan vendor:publish --tag="mimetypes-config"
```

This is the contents of the published config file:

```
return [
    'mime_types_ttl' => 1440, // Default cache duration in minutes
];
```

Usage
-----

[](#usage)

```
use AwaisJameel\MimeTypes\MimeTypes;

//get Extension from Mime Type
try {
    $extension = MimeTypes::getExtensionOrMime('text/html');
    echo $extension; // Output: html
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

//get Mime Type from Extension
try {
    $mimeType = MimeTypesService::getExtensionOrMime('jpg');
    echo $mimeType; // Output: image/jpeg
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

//If the provided MIME type or extension is invalid, the package will throw an exception:
try {
    $result = MimeTypesService::getExtensionOrMime('invalid/mime');
} catch (Exception $e) {
    echo "Error: " . $e->getMessage(); // Output: Invalid MIME type or extension!
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Credits
-------

[](#credits)

- [Awais Jameel](https://github.com/awaisjameel)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[![Latest Version on Packagist](https://camo.githubusercontent.com/1450755ad729852edb5d7b336cc8c8849993d6ab79d163fd81a4cb8a10c4aa5a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61776169736a616d65656c2f6d696d6574797065732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/awaisjameel/mimetypes)[![GitHub Tests Action Status](https://camo.githubusercontent.com/2c9ec222ea86477419ea4a236d64d083ec710bfdeaa9ba9f7ba49d802c283385/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61776169736a616d65656c2f6d696d6574797065732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/awaisjameel/mimetypes/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/b9a7ace2668e6222b042b4ae2fcb8bff9c95782d4266382da18c9e07e68ef359/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61776169736a616d65656c2f6d696d6574797065732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/awaisjameel/mimetypes/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/e1f78799f44e81ce0c0c0511ab794a132f796b5417ba1415f3c309469a32c0d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61776169736a616d65656c2f6d696d6574797065732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/awaisjameel/mimetypes)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance70

Regular maintenance activity

Popularity8

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.4% 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

464d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8478f5cd00831255bda5f4ab259a8761a8001142756ab90bf8804388a78b2036?d=identicon)[awaisjameel](/maintainers/awaisjameel)

---

Top Contributors

[![awaisjameel](https://avatars.githubusercontent.com/u/9046343?v=4)](https://github.com/awaisjameel "awaisjameel (11 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")

---

Tags

laravelAwaisJameelmimetypesmimetype-to-extensionextension-to-mimetype

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/awaisjameel-mimetypes/health.svg)

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

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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