1. Go to this page and download the library: Download codeinc/media-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/ */
codeinc / media-types example snippets
use CodeInc\MediaTypes\MediaTypes;
// looking up the media type of a file, a path or an URL
// (or anything finishing by an extension)
MediaTypes::getFilenameMediaType('/path/to/a/picture.jpg'); // -> 'image/jpeg'
// looking up the media type for an extension
MediaTypes::getExtensionMediaType('jpg'); // -> 'image/jpeg'
// listing all known extensions for a media type
MediaTypes::getMediaTypeExtensions('image/jpeg'); // -> ['jpeg', 'jpg', 'jpe']
// listing all media types
var_dump(MediaTypes::getMediaTypes()); // assoc array
// searching for media types using a shell pattern
var_dump(MediaTypes::searchMediaTypes('image/*'); // -> assoc array
use CodeInc\MediaTypes\MediaTypes;
// listing all types
foreach (new MediaTypes() as $extension => $mediaType) {
var_dump($extension, $mediaType);
}
use CodeInc\MediaTypes\MediaTypes;
$mediaTypes = new MediaTypes();
// you can test the existence or either an extension or a media type
var_dump(isset($mediaTypes['jpg'])); // -> true
var_dump(isset($mediaTypes['image/jpeg'])); // -> true
var_dump(isset($mediaTypes['a-fake/media-type'])); // -> false
// you can access an extension's media type
var_dump($mediaTypes['jpg']); // -> 'image/jpeg'
// and a media type's extensions
var_dump($mediaTypes['image/jpeg']); // -> ['jpeg', 'jpg', 'jpe']
// if the type does not exist, the value is null
var_dump($mediaTypes['a-fake/media-type']; // -> null
bash
php scripts/generate-media-types-list.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.