1. Go to this page and download the library: Download devanych/mime-types library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
devanych / mime-types example snippets
use Devanych\Mime\MimeTypes;
$mimeTypes = new MimeTypes();
/**
* Gets the MIME types for the given file extension.
*
* @param string $extension
* @return string[] an array of MIME types or an empty array if no match is found
*/
$mimeTypes->getMimeTypes('jpeg'); // ['image/jpeg', 'image/pjpeg']
/**
* Gets the file extensions for the given MIME type.
*
* @param string $mimeType
* @return string[] an array of extensions or an empty array if no match is found
*/
$mimeTypes->getExtensions('image/jpeg'); // ['jpeg', 'jpg', 'jpe']
/**
* Adds a custom map of MIME types and file extensions.
*
* The key is a MIME type and the value is an array of extensions.
*
* Example code:
*
* $map = [
* 'image/ico' => ['ico'],
* 'image/icon' => ['ico'],
* 'image/jp2' => ['jp2', 'jpg2'],
* 'image/jpeg' => ['jpeg', 'jpg', 'jpe'],
* 'image/jpeg2000' => ['jp2', 'jpg2'],
* ];
*
* If the map format is invalid, an `\InvalidArgumentException` will be thrown when the map is added.
*
* @param array $map
*/
$mimeTypes->addMap($map);