PHP code example of wgenial / php-mimetyper

1. Go to this page and download the library: Download wgenial/php-mimetyper 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/ */

    

wgenial / php-mimetyper example snippets


use MimeTyper\Repository\MimeDbRepository;

$mimeRepository = new MimeDbRepository();

$mimeRepository->findExtensions("image/jpeg"); // ["jpeg","jpg","jpe"]
$mimeRepository->findExtension("image/jpeg"); // "jpeg"

$mimeRepository->findType("html"); // "html"
$mimeRepository->findType("js"); // 'application/javascript'



use MimeTyper\Repository\ExtendedRepository;

$mimeRepostory = new ExtendedRepository();

$mimeRepository->findExtensions("text/x-php"); // ["php", "php2", "php3", "php4", "php5"]

$mimeRepository->findTypes("php"); // ["text/x-php", "application/x-php", "text/php", "application/php", "application/x-httpd-php"]
$mimeRepository->findType("php"); // "text/x-php"



use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;

use MimeTyper\Repository\ExtendedRepository;
use MimeTyper\Symfony\ExtraMimeTypeExtensionGuesser;

$symfonyGuesser = ExtensionGuesser::getInstance();
$extraGuesser = new ExtraMimeTypeExtensionGuesser(
    new ExtendedRepository()
);
$symfonyGuesser->register($extraGuesser);