1. Go to this page and download the library: Download league/mime-type-detection 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/ */
league / mime-type-detection example snippets
$detector = new League\MimeTypeDetection\FinfoMimeTypeDetector();
// Detect by contents, fall back to detection by extension.
$mimeType = $detector->detectMimeType('some/path.php', 'string contents');
// Detect by contents only, no extension fallback.
$mimeType = $detector->detectMimeTypeFromBuffer('string contents');
// Detect by actual file, no extension fallback.
$mimeType = $detector->detectMimeTypeFromFile('existing/path.php');
// Only detect by extension
$mimeType = $detector->detectMimeTypeFromPath('any/path.php');
// Constructor options
$detector = new League\MimeTypeDetection\FinfoMimeTypeDetector(
$pathToMimeDatabase, // Custom mime database location, default: ''
$customExtensionMap, // Custom extension fallback mapp, default: null
$bufferSampleSize // Buffer size limit, used to take a sample (substr) from the input buffer to reduce memory consumption.
);
$detector = new League\MimeTypeDetection\ExtensionMimeTypeDetector();
// Only detect by extension, ignores the file contents
$mimeType = $detector->detectMimeType('some/path.php', 'string contents');
// Always returns null
$mimeType = $detector->detectMimeTypeFromBuffer('string contents');
// Only detect by extension
$mimeType = $detector->detectMimeTypeFromFile('existing/path.php');
// Only detect by extension
$mimeType = $detector->detectMimeTypeFromPath('any/path.php');
$map = new League\MimeTypeDetection\GeneratedExtensionToMimeTypeMap();
// string mime-type or NULL
$mimeType = $map->lookupMimeType('png');
$innerMap = new League\MimeTypeDetection\GeneratedExtensionToMimeTypeMap();
$map = new League\MimeTypeDetection\OverridingExtensionToMimeTypeMap($innerMap, ['png' => 'custom/mimetype']);
// string "custom/mimetype"
$mimeType = $map->lookupMimeType('png');