xobotyi/php-mime-type

A comprehensive MIME-types lib for PHP.

Fund package maintenance!
Patreon

v1.2.0 2019-01-23 14:25 UTC

This package is auto-updated.

Last update: 2022-07-21 20:22:33 UTC


README

68747470733a2f2f706f7365722e707567782e6f72672f786f626f7479692f7068702d6d696d652d747970652f76657273696f6e3f666f726d61743d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f786f626f7479692f7068702d6d696d652d747970652e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f67726164652f31306335616630303030373934396232383061386438613036323432383031612e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f636f7665726167652f31306335616630303030373934396232383061386438613036323432383031612e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f706f7365722e707567782e6f72672f786f626f7479692f7068702d6d696d652d747970652f646f776e6c6f6164733f666f726d61743d666c61742d737175617265 68747470733a2f2f706f7365722e707567782e6f72672f786f626f7479692f7068702d6d696d652d747970652f6c6963656e73653f666f726d61743d666c61742d737175617265

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)