A comprehensive MIME-types lib for PHP
A comprehensive MIME-type lib allowing you to get known file extensions by mime-type and vice-versa.
It uses mime-db underneath as it is most thorough and recent mime-types list, aggregated from IANA, Apache and nginx
composer require xobotyi/php-mime-type
<?php
use xobotyi\MimeType;
MimeType::getExtensions('text/plain'); // ['txt', 'text', 'conf', 'def', 'list', 'log', 'in', 'ini']
MimeType::getExtensionMimes('wav'); // ['audio/wav', 'audio/wave', 'audio/x-wav']
Description: Check whether mime-type is supported.
Parameters: $type - mime-type to check.
Return: boolean
Description: Return the mime-type's associated extensions.
Return: plain array of strings or null if mime-type is unknown
Description: Return the plain list of supported mime-types.
Parameters: $group - group of mime-types to return (group is string before the slash, 4ex: text, video).
Return: plain array of strings.
Description: Check whether file extension is supported.
Parameters: $extension - extension to check (without leading dot).
Return: bool
Description: Return known relative mime-types
Return: Array (null if extension is unknown), even for extensions that associated with a single mime-type.
This is made for return values monotony, due to some extensions are associated with more than one mime-type.
Description: Return the plain list of supported file extensions.
Return: plain array of strings or numbers (some file extensions are numbers only so the treated as integer)