league/mime-type-detection
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The league/mime-type-detection package is a versatile and robust tool for detecting mime-types in PHP. It provides a consistent interface, making it a crucial ally in handling file uploads, downloads, or working with local files. Whether you need mime-type detection based on a file's content, its name, or a combination of both, this package has you covered. It's an essential part of the PHP League's collection and a mainstay in many PHP-based projects.
To use the league/mime-type-detection package, you first need to install it using Composer:
composer require league/mime-type-detection
Usage is then pretty straightforward; you create a new instance of a detector and call the relevant methods. Depending on whether you want a detection based on file contents, file name, or both, you'd use different methods.
To detect by contents, fall back to detection by extension:
$detector = new League\MimeTypeDetection\FinfoMimeTypeDetector();
$mimeType = $detector->detectMimeType('some/path.php', 'string contents');
To detect by contents only, without extension fallback:
$mimeType = $detector->detectMimeTypeFromBuffer('string contents');
To detect by actual file, no extension fallback:
$mimeType = $detector->detectMimeTypeFromFile('existing/path.php');
To only detect by extension:
$mimeType = $detector->detectMimeTypeFromPath('any/path.php');
The league/mime-type-detection package's documentation can be found on its GitHub page at https://github.com/thephpleague/mime-type-detection. The README file there provides a comprehensive guide on how to use the package, its features, its methods, and the contracts it offers for mime-type detection and extension lookup. It's a valuable resource for beginners and experienced developers alike who use this package.