PHP code example of componenta / mimetype-detector
1. Go to this page and download the library: Download componenta/mimetype-detector 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/ */
componenta / mimetype-detector example snippets
use Componenta\Detector\MimeType;
$mime = new MimeType('text/html; charset=utf-8');
$mime->value; // text/html
$mime->type; // text
$mime->subtype; // html
$mime->charset; // utf-8
$mime->isText(); // true
$mime->isWebSafe(); // true
use Componenta\Detector\Ext;
$ext = new Ext('.JPG');
$ext->value; // jpg
$ext->withDot(); // .jpg
$ext->isImage(); // true
use Componenta\Detector\MimeMap;
$map = new MimeMap();
$map->getExtension('image/jpeg'); // jpg
$map->getMimeType('jpg'); // image/jpeg
$map->extend(['application/x-custom' => ['custom']]);
use Componenta\Detector\FinfoDetector;
use Componenta\Detector\MimeTypeDetectorInterface;
/** @var MimeTypeDetectorInterface $detector */
$detector = new FinfoDetector();
$detector->detectMimeType('plain text'); // text/plain
$detector->detectExtension('plain text'); // txt
$detector->detectFileMimeType('/path/to/file.txt');
$detector->detectFileExtension('/path/to/file.txt');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.