xobotyi / php-mime-type
A comprehensive MIME-types lib for PHP.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Fund package maintenance!
Patreon
Installs: 7 242
Dependents: 0
Suggesters: 0
Security: 0
Stars: 31
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
Requires (Dev)
- ext-curl: *
- ext-json: *
- codacy/coverage: 1.4.2
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2022-07-21 20:22:33 UTC
README
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
Install
composer require xobotyi/php-mime-type
Usage
<?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']
API
MimeType::isSupported(string $type)
Description: Check whether mime-type is supported.
Parameters: $type - mime-type to check.
Return: boolean
MimeType::getExtensions(string $mime)
Description: Return the mime-type's associated extensions.
Return: plain array of strings or null if mime-type is unknown
MimeType::getSupportedMimes(string $group = null)
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.
MimeType::isSupportedExtension(string $extension)
Description: Check whether file extension is supported.
Parameters: $extension - extension to check (without leading dot).
Return: bool
MimeType::getExtensionMimes()
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.
MimeType::getSupportedExtensions()
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)