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.
.php uploads disguised as .jpg files) by cross-referencing content with extensions..exe).Adopt if:
.txt file with binary data or a .jpg with corrupt headers).document)..pkpass, .caf, .svg).Look elsewhere if:
spatie/laravel-medialibrary).filetype npm package).For Executives:
*"This package solves a critical but often overlooked risk in file uploads: misleading extensions. For example, a user could upload a .php file disguised as .jpg, exposing our system to code injection. By detecting file types via both filename and content, we:
For Engineers:
*"Problem: File extensions are unreliable. A .pdf could be a ZIP bomb, or a .jpg might be a shell script.
Solution: brandembassy/file-type-detector is a forked, maintained version of FileTypeDetector with:
.webp support).How to Use:
use BrandEmbassy\FileTypeDetector\Detector;
// Validate uploads:
$detection = Detector::detectByContent($_FILES['file']['tmp_name']);
if (!$detection || $detection[2] !== 'image/jpeg') {
abort(400, 'Invalid file type');
}
// Get MIME type for processing:
$mime = Detector::getMimeType($file);
Tradeoffs:
Recommendation: Use for security validation and file routing. Pair with Laravel’s Validate rules for extension checks and this package for content verification."*
How can I help you explore Laravel packages today?