{"id":20128942,"url":"https://github.com/intervention/mimesniffer","last_synced_at":"2025-04-09T13:04:55.800Z","repository":{"id":56992736,"uuid":"198071049","full_name":"Intervention/mimesniffer","owner":"Intervention","description":"A library to detect mime types of binary content","archived":false,"fork":false,"pushed_at":"2025-03-30T09:22:25.000Z","size":88,"stargazers_count":22,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T10:25:40.771Z","etag":null,"topics":["mime","mime-parser","mime-types"],"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/Intervention.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["Intervention"],"ko_fi":"interventionphp","custom":"https://paypal.me/interventionio"}},"created_at":"2019-07-21T15:06:28.000Z","updated_at":"2025-03-30T09:22:28.000Z","dependencies_parsed_at":"2022-08-21T10:40:52.952Z","dependency_job_id":"b16a6ecf-e41d-4b0d-9e4f-df2e45754f4c","html_url":"https://github.com/Intervention/mimesniffer","commit_stats":{"total_commits":66,"total_committers":1,"mean_commits":66.0,"dds":0.0,"last_synced_commit":"030c50610284d655708438a0f71b4621e353b7f3"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intervention%2Fmimesniffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intervention%2Fmimesniffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intervention%2Fmimesniffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intervention%2Fmimesniffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Intervention","download_url":"https://codeload.github.com/Intervention/mimesniffer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248045230,"owners_count":21038553,"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":["mime","mime-parser","mime-types"],"created_at":"2024-11-13T20:30:39.669Z","updated_at":"2025-04-09T13:04:55.773Z","avatar_url":"https://github.com/Intervention.png","language":"PHP","funding_links":["https://github.com/sponsors/Intervention","https://ko-fi.com/interventionphp","https://paypal.me/interventionio"],"categories":[],"sub_categories":[],"readme":"# PHP Media type (MIME) detector\n\n[![Latest Version](https://img.shields.io/packagist/v/intervention/mimesniffer.svg)](https://packagist.org/packages/intervention/mimesniffer)\n[![Tests](https://github.com/Intervention/mimesniffer/actions/workflows/build.yml/badge.svg)](https://github.com/Intervention/mimesniffer/actions/workflows/build.yml)\n[![Monthly Downloads](https://img.shields.io/packagist/dm/intervention/mimesniffer.svg)](https://packagist.org/packages/intervention/mimesniffer/stats)\n[![Support me on Ko-fi](https://raw.githubusercontent.com/Intervention/mimesniffer/main/.github/images/support.svg)](https://ko-fi.com/interventionphp)\n\nDetecting MIME Content-type in PHP is easy with\n[mime_content_type](https://www.php.net/manual/en/function.mime-content-type.php)\nor [Fileinfo](https://www.php.net/manual/en/book.fileinfo.php). But Fileinfo as\nan extension is sometimes not available on the server. The function\n`mime_content_type` wants a path to the filesystem as argument and doesn't\nprocess if we only have a string value. This package makes it easy to detect\nthe mime types of the content of a given file or string, without any extension\ndependencies. \n\n## Installation\n\nInstall the package easily via composer:\n\n```bash\ncomposer require intervention/mimesniffer\n```\n## Usage\n\nHere are some code samples, to show how the library is handled.\n\n```php\nuse Intervention\\MimeSniffer\\MimeSniffer;\nuse Intervention\\MimeSniffer\\Types\\ImageJpeg;\n\n// universal factory method\n$sniffer = MimeSniffer::create($content);\n\n// or detect given string\n$sniffer = MimeSniffer::createFromString($content);\n\n// or detect given file\n$sniffer = MimeSniffer::createFromFilename('image.jpg');\n\n// or detect from file pointer\n$sniffer = MimeSniffer::createFromFilename(fopen('test.jpg', 'r'));\n\n// returns object of detected type \n$type = $sniffer-\u003egetType(); \n\n$bool = $type-\u003eisBinary(); // check if we have binary data\n$bool = $type-\u003eisImage(); // check if we are dealing with an image\n$bool = $type-\u003eisVideo(); // check video data was detected\n$bool = $type-\u003eisAudio(); // check if we have detected audio data\n$bool = $type-\u003eisArchive(); // check if an archive was detected\n$type = (string) $type; // cast type to string (e.g. \"image/jpeg\")\n\n// you can also check, if the content matches a specific type\n$bool = $sniffer-\u003ematches(new ImageJpeg);\n\n// or check, if the content matches an array of types\n$bool = $sniffer-\u003ematches([ImageJpeg::class, ImageGif::class]);\n\n// or check, if the content matches an array of type objects\n$bool = $sniffer-\u003ematches([new ImageJpeg, $type]);\n```\n\nIf your prefer non-static initialization:\n\n```php\nuse Intervention\\MimeSniffer\\MimeSniffer;\n\n// create instance with constructor\n$sniffer = new MimeSniffer($content);\n\n// with setter for given content\n$type = $sniffer-\u003esetFromString($other_content)-\u003egetType();\n\n// or with setter for filename\n$type = $sniffer-\u003esetFromFilename('images/image.jpg')-\u003egetType();\n\n// or with setter for file pointer\n$type = $sniffer-\u003esetFromPointer(fopen('images/image.jpg', 'r'))-\u003egetType();\n```\n\n**Currently only the following file types can be detected. More will be added in a next release.**\n\n### Images\n\n- Image encoded as JPEG raw or in the JFIF or Exif file format\n- Image file encoded in the Graphics Interchange Format (GIF)\n- Image encoded in the Portable Network Graphics format (PNG)\n- Image encoded as BMP file, a bitmap format\n- Image encoded in High Efficiency Image File Format (HEIC/HEIF)\n- Icon encoded in ICO file format\n- Image in Google WebP image format\n- Scalable Vector Graphics (SVG)\n- Tagged Image File Format (TIFF)\n- Image encoded Photoshop Document file format (PSD)\n- AV1 Image File Format (AVIF)\n- JPEG 2000 File Format\n\n### Archives\n\n- GZIP compressed\n- ZIP file\n- RAR archive\n- TAR file\n\n### Videos\n\n- AVI\n- MPEG-1 and MPEG-2 video \n- MKV media container\n\n### Audio\n\n- MP3 file\n- FLAC file\n\n### Other\n\n- PDF document\n- OGG media container\n- SQLite Database\n- application/octet-stream (default binary)\n- text/plain (default)\n\n## Contributing\n\nContributions are welcome. Please note the following guidelines before submiting your pull request.\n\n- Follow [PSR-2](http://www.php-fig.org/psr/psr-2/) coding standards.\n- Write tests for new functions and added features\n\n## Development \u0026 Testing\n\nWith this package comes a Docker image to build a test suite and analysis\ncontainer. To build this container you have to have Docker installed on your\nsystem. You can run all tests with this command.\n\n```bash\ndocker-compose run --rm --build tests\n```\n\nRun the static analyzer on the code base.\n\n```bash\ndocker-compose run --rm --build analysis\n```\n\n## Authors\n\nThis library is developed and maintained by [Oliver Vogel](https://intervention.io)\n\n## License\n\nIntervention MimeSniffer is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintervention%2Fmimesniffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintervention%2Fmimesniffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintervention%2Fmimesniffer/lists"}