adrienrn/php-mimetyper
A lightweight PHP library for MIME type mapping. Look up MIME types by file extension and extensions by MIME type through a simple API, useful for uploads, validation, and content headers without relying on file inspection.
.jpg that arrives as application/octet-stream, an .xlsx rejected because the client sent application/zip).mime-db corpus and its upkeep. This forces the right framing: you are not buying a library, you are subscribing to a mapping table. If your team would otherwise hand-maintain a 200-line array of extensions, that array will be stale within two quarters — new formats (AVIF, HEIC, JXL, WebP variants, Office Open XML sub-types) land faster than most teams notice.Content-Type on delivery. Every download, invoice PDF, generated report, or user-uploaded asset served through Storage::download() / response()->file() depends on this mapping. A roadmap item like "self-serve media library" or "customer-facing document portal" implicitly assumes reliable type resolution; if it's wrong, browsers download instead of render, or render when they shouldn't.jshttp/mime-db — the same source Node's mime-types uses. If you run a PHP backend with a Node/TypeScript frontend, or are migrating services, this is a route to identical type resolution on both sides, which kills a class of "works in the uploader, fails in the API" bugs.finfo/libmagic content inspection.type → extensions). Less obvious but real: deciding canonical extensions for export filenames, CDN cache-key suffixes, or "download as" menus.Adopt when:
mime-db as the source of truth.image/jpeg, what extensions are valid?) as a first-class operation rather than an afterthought.Look elsewhere when:
mimes: / mimetypes: rules and UploadedFile::getMimeType() already work via Symfony Mime, which ships with the framework. Adding a second mapping source creates two truth-tellers that will eventually disagree. Confirm the gap before adopting.finfo_file, ClamAV, re-encoding images) plus size limits and storage isolation. Do not let a mapping library stand in for that control.mime-db JSON yourself and write the 50-line lookup — MIT licensing makes that legitimate. Budget that as a fallback, not a failure.Decision rule: if two or more of {cross-stack parity, standalone/no-framework, reverse lookup} hold, adopt with a pinned version and a wrapper interface of your own. If none hold, use what the framework already gives you.
For executives: This is a small, low-cost dependency that replaces a hand-maintained lookup table with a continuously curated one, sourced from the same dataset the JavaScript ecosystem uses. The business value is in defect prevention, not features: fewer broken uploads, fewer mis-served documents, fewer "my file won't attach" support tickets. Cost is near zero; the material risk is maintenance — one maintainer, small community — which we mitigate by pinning a version behind our own thin interface and treating the underlying data as replaceable. Recommendation: adopt narrowly where it closes a real gap, do not adopt where the framework already covers it.
For engineering: It's a mime-db-backed mapper with Symfony/Laravel compatibility — bidirectional type/extension resolution, no content sniffing. It does not replace finfo, upload validation hardening, or image processing. Treat it as a data dependency: pin the version, refresh quarterly, and hide it behind a single internal service so a swap to vendored data is a one-file change. Be explicit that on Laravel, mimes:/mimetypes: already resolve through Symfony Mime — so the justification here has to be cross-stack parity, standalone use, or reverse lookups, not "we need MIME types."
How can I help you explore Laravel packages today?