PHP code example of ab / lib-mime
1. Go to this page and download the library: Download ab/lib-mime 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/ */
ab / lib-mime example snippets
use ab\Mime\MimeTypeArray;
(function () {
$tryPath = $_SERVER['REQUEST_URI'];
$filename = basename($tryPath);
[$fileext,] = explode('.', strrev($filename), 2);
$fileext = strrev($fileext);
// ....
$type = MimeTypeArray::getContentType($fileext);
if ($type !== null) {
header("Content-Type: $type", true);
} else {
header("Content-Type: application/octet-stream", true);
}
// ...
}());