Download the PHP package moudarir/mime-detector without Composer
On this page you can find all versions of the php package moudarir/mime-detector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download moudarir/mime-detector
More information about moudarir/mime-detector
Files in moudarir/mime-detector
Package mime-detector
Short Description A PHP library for detecting the real MIME type of files by analyzing their content.
License MIT
Homepage https://github.com/moudarir/mime-detector
Informations about the package mime-detector
MIME Detector
⚠️ Deprecated
moudarir/mime-detectoris no longer maintained and has been deprecated in favor ofmoudarir/file.The new package provides file resource management, file metadata and MIME type detection in a single abstraction.
New projects should use
moudarir/fileinstead.
A PHP library for detecting the real MIME type of files by analyzing their content.
Unlike extension-based detection, this library relies on multiple detection strategies:
- binary signatures (magic numbers);
- ZIP container analysis;
- text format inspection;
- ISO Base Media analysis (MP4, MOV, AVIF, HEIC...);
- RIFF container analysis (WEBP, WAV, AVI...);
- PHP FileInfo/libmagic detection.
The goal is to provide a reliable MIME type detection based on the actual file content.
Requirements
- PHP >= 8.4
fileinfoextensionzipextension for ZIP container analysis
Installation
Install the package using Composer:
Detection Process
The detection pipeline follows a strict order:
Each detector returns:
- a
DetectionResultwhen it recognizes the file; nullwhen it cannot identify it.
The first successful detection is returned.
Supported Formats
Images
- JPEG
- PNG
- GIF
- BMP
- TIFF
- WEBP
- AVIF
- HEIC
- HEIF
- ICO
- SVG
Documents
- DOCX
- XLSX
- PPTX
- ODT
- ODS
- ODP
- EPUB
Archives
- ZIP
- 7z
- RAR
- GZIP
- BZIP2
- XZ
ZIP-based Containers
The library can identify specialized ZIP containers by inspecting their internal structure.
Microsoft Office Open XML
- DOCX
- XLSX
- PPTX
OpenDocument
- ODT
- ODS
- ODP
Other containers
- EPUB
- APK
- JAR
Detection is based on the internal ZIP structure, not the file extension.
Audio
- MP3
- FLAC
- OGG
- WAV
- M4A
Video
- MP4
- MOV
- AVI
- Matroska
- WebM
- 3GP
Executables
- ELF
- Windows PE
Disk Image
- ISO 9660
- Apple Disk Image
DMG
Text Formats
The library detects common text-based formats:
- PHP
- JSON
- XML
- HTML
- SVG
- CSS
- JavaScript
- Markdown
- YAML
- SQL
Generic text files are handled by PHP FileInfo when no specialized format is detected.
Separated Values
- CSV
- TSV
Example
Detecting a PDF file:
Output:
Mime Type
Detector
Metadata
Design Principles
Content over extension
The file extension is never used as the primary source of truth.
Example:
A file named:
containing a PDF document will be detected as:
Performance Considerations
The library includes several optimizations:
- preload of the file header;
- caching of binary header data;
- caching of hexadecimal header representation;
- stopping detection as soon as a detector succeeds;
- avoiding ZIP parsing unless the file is identified as a ZIP archive.
Limitations
MIME detection is not a complete security validation mechanism.
A file can have a valid MIME type while still containing malicious content.
This library should not replace:
- antivirus scanning;
- application-level validation;
- security policies.
It only identifies the actual file format.
License
MIT License
All versions of mime-detector with dependencies
ext-fileinfo Version *
ext-zip Version *