The FinfoMimeTypeDetector uses finfo to detect mimetypes by file contents and can fall back to extension detection if needed.
Constructor Options:
$pathToMimeDatabase (string): Custom mime database location. Default is ''.$customExtensionMap (array|null): Custom extension fallback map. Default is null.$bufferSampleSize (int): Buffer size limit used to take a sample (substr) from the input buffer to reduce memory consumption.
$detector = new League\MimeTypeDetection\FinfoMimeTypeDetector();
// Detect by contents, fall back to detection by extension.
$mimeType = $detector->detectMimeType('some/path.php', 'string contents');
// Detect by contents only, no extension fallback.
$mimeType = $detector->detectMimeTypeFromBuffer('string contents');
// Detect by actual file, no extension fallback.
$mimeType = $detector->detectMimeTypeFromFile('existing/path.php');
// Only detect by extension
$mimeType = $detector->detectMimeTypeFromPath('any/path.php');