{"id":35799868,"url":"https://github.com/adrienrn/php-mimetyper","last_synced_at":"2026-01-07T11:00:07.538Z","repository":{"id":56941221,"uuid":"66544934","full_name":"adrienrn/php-mimetyper","owner":"adrienrn","description":"PHP mime type and extension mapping library: built with jshttp/mime-db, compatible with Symfony and Laravel","archived":false,"fork":false,"pushed_at":"2023-07-14T02:47:28.000Z","size":40,"stargazers_count":24,"open_issues_count":4,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-07T00:56:10.391Z","etag":null,"topics":["laravel","mime-types","php","php-mime","symfony"],"latest_commit_sha":null,"homepage":"","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/adrienrn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-25T09:31:32.000Z","updated_at":"2025-07-11T19:52:55.000Z","dependencies_parsed_at":"2024-06-18T15:14:39.606Z","dependency_job_id":"651252a5-9b5f-4858-912b-9e9a52b87be5","html_url":"https://github.com/adrienrn/php-mimetyper","commit_stats":{"total_commits":27,"total_committers":4,"mean_commits":6.75,"dds":"0.18518518518518523","last_synced_commit":"702e00a604b4baed34d69730ce055e05c0f43932"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/adrienrn/php-mimetyper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrienrn%2Fphp-mimetyper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrienrn%2Fphp-mimetyper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrienrn%2Fphp-mimetyper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrienrn%2Fphp-mimetyper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adrienrn","download_url":"https://codeload.github.com/adrienrn/php-mimetyper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrienrn%2Fphp-mimetyper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28234794,"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","status":"online","status_checked_at":"2026-01-07T02:00:05.975Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["laravel","mime-types","php","php-mime","symfony"],"created_at":"2026-01-07T11:00:00.604Z","updated_at":"2026-01-07T11:00:07.521Z","avatar_url":"https://github.com/adrienrn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-mimetyper\n\nPHP mime type and extension mapping library: built with [jshttp/mime-db](http://github.com/jshttp/mime-db), compatible with Symfony and Laravel.\n\n```php\nuse MimeTyper\\Repository\\MimeDbRepository;\n\n$mimeRepository = new MimeDbRepository();\n\n$mimeRepository-\u003efindExtensions(\"image/jpeg\"); // [\"jpeg\",\"jpg\",\"jpe\"]\n$mimeRepository-\u003efindExtension(\"image/jpeg\"); // \"jpeg\"\n\n$mimeRepository-\u003efindType(\"html\"); // \"html\"\n$mimeRepository-\u003efindType(\"js\"); // 'application/javascript'\n\n```\n\n\u003e The most complete and up-to-date mime type mapping for PHP!\n\nThe goal is to provide a complete and up-to-date mime types mapping for PHP and build a comprehensive and simple interface for PHP. This package is heavily inspired from [dflydev](https://github.com/dflydev/dflydev-apache-mime-types) work and extends it.\n\n## Mime types mapping, the right way.\n\nThis library uses [jshttp/mime-db](http://github.com/jshttp/mime-db) as its default mapping which aggregates data from multiple sources and creates a single `db.json` making it the most complete two ways mapping, from mime to extension and extension to mime types too.\n\n- [IANA](http://www.iana.org/assignments/media-types/media-types.xhtml)\n- [Apache](http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types)\n- [Nginx](http://hg.nginx.org/nginx/file/tip/conf/mime.types)\n- Some (very) useful custom aliases;\n\n## Custom mime types and custom repositories\n\nSome custom types (aliases really) are maintained locally too, in the same JSON format as jshttp/mime-db. \n\n```php\n\nuse MimeTyper\\Repository\\ExtendedRepository;\n\n$mimeRepostory = new ExtendedRepository();\n\n$mimeRepository-\u003efindExtensions(\"text/x-php\"); // [\"php\", \"php2\", \"php3\", \"php4\", \"php5\"]\n\n$mimeRepository-\u003efindTypes(\"php\"); // [\"text/x-php\", \"application/x-php\", \"text/php\", \"application/php\", \"application/x-httpd-php\"]\n$mimeRepository-\u003efindType(\"php\"); // \"text/x-php\"\n\n```\n\nThe reason to maintain aliases locally helps with overall compatibility between mime type guessing methods. Tools detecting mime types don't always return standard mime type or the standard mime type does not exist. All of those custom mime types might be [added to jshttp/mime-db custom types in the end](https://github.com/jshttp/mime-db/issues/49).\n\n**Example:** Debian will detect a PHP file as `text/x-php` while browsers will send `application/x-httpd-php`. It goes the same with files such as Javascript (`application/javascript` vs `text/javascript`) or Microsoft Office / Libre Office files.\n\nDon't hesitate to make a pull request to discuss this.\n\n## Mime types for Symfony and Laravel\n\nThis library is compatible with your Symfony or Laravel app to enjoy the completeness of the mapping.\n\nUse the `ExtraMimeTypeExtensionGuesser` as a bridge class between Symfony `ExtensionGuesser` and this package `RepositoryInterface`.\n\n```php\n\nuse Symfony\\Component\\HttpFoundation\\File\\MimeType\\ExtensionGuesser;\n\nuse MimeTyper\\Repository\\ExtendedRepository;\nuse MimeTyper\\Symfony\\ExtraMimeTypeExtensionGuesser;\n\n$symfonyGuesser = ExtensionGuesser::getInstance();\n$extraGuesser = new ExtraMimeTypeExtensionGuesser(\n    new ExtendedRepository()\n);\n$symfonyGuesser-\u003eregister($extraGuesser);\n\n```\n\nThis example uses the `ExtendedRepository` (mime-db and local custom mime types), you can use the default `MimeDbRepository`, implement your own or use a `CompositeRepository` to aggregate multiple repostories.\n\n## Safe detection of mime type in PHP\n\nBefore mapping type to extension or extension to type, you need to be able to properly detect the mime type of a file.\n\nFor security reasons, **do not trust browsers**, eg `$_FILES['your_file']['type']`, when it comes to detect the mime type of a file.\n\nTo safely detect the mime type of a file, . Symfony is giving a great example with their MimeTypeGuesser implementation of:\n\n- [FileinfoMimeTypeGuesser](https://github.com/symfony/http-foundation/blob/3.1/File/MimeType/FileinfoMimeTypeGuesser.php)\n- [FileBinaryMimeTypeGuesser](https://github.com/symfony/http-foundation/blob/3.1/File/MimeType/FileBinaryMimeTypeGuesser.php)\n\nIt all ends up inspecting the file using [finfo](http://php.net/manual/en/function.finfo-open.php) and relies on magic db files. PHP will use its own magic db or your system magic db depending on your environement.\n\n## Other PHP libraries for mime types\n\n- [dflydev/dflydev-apache-mime-types](https://github.com/dflydev/dflydev-apache-mime-types)\n\n  Uses `mime.types` Apache file, comprehensive api. As stated before, php-mimetyper is heavily inspired by this, extending it to be a bit more complete using an external mapping and a wider interface.\n\n- [symfony/http-foundation](https://github.com/symfony/http-foundation/tree/master/File/MimeType)\n\n  Symfony provides a nice interface for guessing mime types and extensions but uses only a local mapping based on Apache registry, see above to bridge it to this package.\n\n- [davidpersson/mm](https://github.com/davidpersson/mm)\n\n  Library for media processing and mime type and extension guessing. Uses FreeDesktop magic.db file for the latter.\n\n- [Hoa/Mime](https://github.com/hoaproject/Mime)\n\n  The Hoa package to deal with mime types. Uses `mime.types` Apache file (local fallback) and relies on static methods.\n\n- [karwana/php-mime](https://github.com/karwana/php-mime)\n  \n  Uses `mime.types` Apache file and finfo, requires PHP \u003e=5.4.\n\n- [PEAR/MIME_Type](https://github.com/pear/MIME_Type)\n\n  Detect the mime type of a file: uses internally finfo_file, mime_content_type or file command to guess the mime type.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrienrn%2Fphp-mimetyper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadrienrn%2Fphp-mimetyper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrienrn%2Fphp-mimetyper/lists"}