brandembassy/file-type-detector
Detect file type and MIME by filename extension or by inspecting binary/stream content. Returns category, format, and MIME on success (or false). Includes a helper to resolve MIME only. Install via composer: brandembassy/file-type-detector.
Project forked from https://github.com/wapmorgan/FileTypeDetector
Files type detector based on file name extension or file content (binary content).
Detector::detectByFilename(...filename...): array|booleanDetector::detectByContent(...filename/resource...): array|booleanBoth functions will return an array with following elements in case of success:
[0] - Type of file (Detector::AUDIO and so on)[1] - Format of file (Detector::MP3 and so on)[2] - Mime type of file ('audio/mpeg' for example)In case of failure it will return false.
Example:
$type = wapmorgan\FileTypeDetector\Detector::detectByFilename($filename);
// or
$type = wapmorgan\FileTypeDetector\Detector::detectByContent('file-without-extension');
// or
$type = wapmorgan\FileTypeDetector\Detector::detectByContent(fopen('http://somedomain/somepath', 'r'));
To get correct mimetype for file only there is getMimeType($file) function.
$mime = wapmorgan\FileTypeDetector\Detector::getMimeType($file);
// or
$mime = wapmorgan\FileTypeDetector\Detector::getMimeType(fopen('somefile', 'r'));
composer require brandembassy/file-type-detector
How can I help you explore Laravel packages today?