{"id":15089026,"url":"https://github.com/josantonius/php-mime-type","last_synced_at":"2025-10-05T21:31:38.181Z","repository":{"id":57001566,"uuid":"76825008","full_name":"josantonius/php-mime-type","owner":"josantonius","description":"PHP library to get MIME types from extensions","archived":true,"fork":false,"pushed_at":"2023-07-13T18:05:45.000Z","size":1498,"stargazers_count":9,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-02T02:54:50.736Z","etag":null,"topics":["composer","headers-mime","mime-type","mime-types","mimetype","php"],"latest_commit_sha":null,"homepage":"https://josantonius.dev","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/josantonius.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["Josantonius"]}},"created_at":"2016-12-19T03:31:47.000Z","updated_at":"2023-07-13T18:08:34.000Z","dependencies_parsed_at":"2022-08-21T11:30:11.768Z","dependency_job_id":"f22db238-5c99-41cf-87a5-6fc18679be98","html_url":"https://github.com/josantonius/php-mime-type","commit_stats":null,"previous_names":["josantonius/php-mimetype"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josantonius%2Fphp-mime-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josantonius%2Fphp-mime-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josantonius%2Fphp-mime-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josantonius%2Fphp-mime-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josantonius","download_url":"https://codeload.github.com/josantonius/php-mime-type/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219877064,"owners_count":16554821,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","headers-mime","mime-type","mime-types","mimetype","php"],"created_at":"2024-09-25T08:39:17.032Z","updated_at":"2025-10-05T21:31:32.922Z","avatar_url":"https://github.com/josantonius.png","language":"PHP","funding_links":["https://github.com/sponsors/Josantonius"],"categories":[],"sub_categories":[],"readme":"# PHP MimeType library\n\n[![Latest Stable Version](https://poser.pugx.org/josantonius/mime-type/v/stable)](https://packagist.org/packages/josantonius/mime-type)\n[![License](https://poser.pugx.org/josantonius/mime-type/license)](LICENSE)\n[![Total Downloads](https://poser.pugx.org/josantonius/mime-type/downloads)](https://packagist.org/packages/josantonius/mime-type)\n[![CI](https://github.com/josantonius/php-mime-type/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/josantonius/php-mime-type/actions/workflows/ci.yml)\n[![CodeCov](https://codecov.io/gh/josantonius/php-mime-type/branch/main/graph/badge.svg)](https://codecov.io/gh/josantonius/php-mime-type)\n[![PSR1](https://img.shields.io/badge/PSR-1-f57046.svg)](https://www.php-fig.org/psr/psr-1/)\n[![PSR4](https://img.shields.io/badge/PSR-4-9b59b6.svg)](https://www.php-fig.org/psr/psr-4/)\n[![PSR12](https://img.shields.io/badge/PSR-12-1abc9c.svg)](https://www.php-fig.org/psr/psr-12/)\n\nPHP library to get MIME types from extensions.\n\n\u003e The original concept of my project, linking a single mimetype to a file extension, has been found to be insufficient in accurately reflecting the many-to-one relationships that exist in real-world use-cases. In practice, multiple file extensions often correspond to a single mimetype, rendering my existing design approach suboptimal.\n\n\u003e Given these insights, I've decided to archive this repository. I recommend those interested to look at the approach taken by the repository [patrickmccallum/mimetype-io](https://github.com/patrickmccallum/mimetype-io/blob/master/src/mimeData.json). This project adopts a more nuanced perspective, effectively managing mimetypes by acknowledging the possibility of multiple extensions corresponding to a single mimetype. I believe this is a more promising approach for managing mimetypes moving forward.\n\n## Requirements\n\n- Operating System: Linux | Windows.\n\n- PHP versions: 8.0 | 8.1 | 8.2.\n\n## Installation\n\nThe preferred way to install this extension is through [Composer](http://getcomposer.org/download/).\n\nTo install **PHP MimeType library**, simply:\n\n```console\ncomposer require josantonius/mime-type\n```\n\nThe previous command will only install the necessary files,\nif you prefer to **download the entire source code** you can use:\n\n```console\ncomposer require josantonius/mime-type --prefer-source\n```\n\nYou can also **clone the complete repository** with Git:\n\n```console\ngit clone https://github.com/josantonius/php-mime-type.git\n```\n\n## Available Classes\n\n### MimeType\n\n`Josantonius\\MimeType\\MimeType`\n\nGet array with all MIME types:\n\n```php\npublic function all(): array;\n```\n\nGet file extension from MIME type:\n\n```php\npublic function getExtension(string $mimeType): string|null;\n```\n\nGet MIME type from file extension:\n\n```php\npublic function getMime(string $extension): string|null;\n```\n\n### MimeTypeCollection\n\n`Josantonius\\MimeType\\MimeTypeCollection`\n\nGet array with all MIME types:\n\n```php\npublic static function all(): array;\n```\n\nGet file extension from MIME type:\n\n```php\npublic static function getExtension(string $mimeType): string|null;\n```\n\nGet MIME type from file extension:\n\n```php\npublic static function getMime(string $extension): string|null;\n```\n\n## Usage\n\nExample of use for this library:\n\n### Get array with all MIME types\n\n```php\nuse Josantonius\\MimeType\\MimeType;\n\n$mimeType = new MimeType();\n\n$mimeType-\u003eall();\n```\n\n```php\nuse Josantonius\\MimeType\\MimeTypeCollection;\n\nMimeTypeCollection::all();\n```\n\nResult:\n\n```php\n[\n    [\".123\"]=\u003e \"application/vnd.lotus-1-2-3\"\n    [\".3dml\"]=\u003e \"text/vnd.in3d.3dml\"\n    [\".3g2\"]=\u003e \"video/3gpp2\"\n    [\".3gp\"]=\u003e \"video/3gpp\"\n    [\".7z\"]=\u003e \"application/x-7z-compressed\"\n    [\".aab\"]=\u003e \"application/x-authorware-bin\"\n    [\".aac\"]=\u003e \"audio/x-aac\"\n    [\".aam\"]=\u003e \"application/x-authorware-map\"\n    [\".aas\"]=\u003e \"application/x-authorware-seg\"\n    [\".abw\"]=\u003e \"application/x-abiword\"\n    (...)\n]\n```\n\n### Get file extension from MIME type\n\n```php\nuse Josantonius\\MimeType\\MimeType;\n\n$mimeType = new MimeType();\n\n$mimeType-\u003egetExtension('text/html'); // .html\n```\n\n```php\nuse Josantonius\\MimeType\\MimeTypeCollection;\n\nMimeTypeCollection::getExtension('application/zip'); // .zip\n```\n\n### Get MIME type from file extension\n\n```php\nuse Josantonius\\MimeType\\MimeType;\n\n$mimeType = new MimeType();\n\n$mimeType-\u003egetMime('.tar'); // application/x-tar\n\n// The dot can be omitted:\n\n$mimeType-\u003egetMime('mp4'); // video/mp4\n```\n\n```php\nuse Josantonius\\MimeType\\MimeTypeCollection;\n\nMimeTypeCollection::getMime('.json'); // application/json\n```\n\n## Tests\n\nTo run [tests](tests) you just need [composer](http://getcomposer.org/download/)\nand to execute the following:\n\n```console\ngit clone https://github.com/josantonius/php-mime-type.git\n```\n\n```console\ncd PHP-MimeType\n```\n\n```console\ncomposer install\n```\n\nRun unit tests with [PHPUnit](https://phpunit.de/):\n\n```console\ncomposer phpunit\n```\n\nRun code standard tests with [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer):\n\n```console\ncomposer phpcs\n```\n\nRun [PHP Mess Detector](https://phpmd.org/) tests to detect inconsistencies in code style:\n\n```console\ncomposer phpmd\n```\n\nRun all previous tests:\n\n```console\ncomposer tests\n```\n\n## TODO\n\n- [ ] Add new feature\n- [ ] Improve tests\n- [ ] Improve documentation\n- [ ] Improve English translation in the README file\n- [ ] Refactor code for disabled code style rules (see phpmd.xml and phpcs.xml)\n\n## Changelog\n\nDetailed changes for each release are documented in the\n[release notes](https://github.com/josantonius/php-mime-type/releases).\n\n## Contribution\n\nPlease make sure to read the [Contributing Guide](.github/CONTRIBUTING.md), before making a pull\nrequest, start a discussion or report a issue.\n\nThanks to all [contributors](https://github.com/josantonius/php-mime-type/graphs/contributors)! :heart:\n\n## Sponsor\n\nIf this project helps you to reduce your development time,\n[you can sponsor me](https://github.com/josantonius#sponsor) to support my open source work :blush:\n\n## License\n\nThis repository is licensed under the [MIT License](LICENSE).\n\nCopyright © 2016-2023, [Josantonius](https://github.com/josantonius#contact)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosantonius%2Fphp-mime-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosantonius%2Fphp-mime-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosantonius%2Fphp-mime-type/lists"}