mvccore/ext-tool-mimetype-extension

MvcCore - Extension - Tool - MimeType & Extensions - extension to get file mimetype(s) strings array from file extension string or to get file extension(s) strings array from file mimetype string.

v5.0.0 2021-01-18 13:42 UTC

This package is auto-updated.

Last update: 2024-10-17 18:56:14 UTC


README

Latest Stable Version License PHP Version

MvcCore extension to get:

  • Mimetype(s) strings array from file extension string
  • Extension(s) strings array from file mimetype string

This extension doesn't use PHP mime_content_type() function.
To recognize which mimetype has uploaded file by magic bytes does form control (input:file) validator itself using PHP fionfo extension.
This extension has only list of mimetypes and extensions to properly decide, which file extension could be finally stored on server HDD after magic bytes recognition.

Installation

composer require mvccore/ext-tool-mimetype-extension

Mimetypes And Extensions Sources

Database of all mimetypes and extensions is loaded by Node.JS project jshttp/mime-db from 4 sources:

Usage

use \MvcCore\Ext\Tools;

$mimeTypes = Tools\MimeTypesExtensions::GetMimeTypesByExtension('dmg');
// ['application/x-apple-diskimage', 'application/octet-stream']
var_dump($mimeTypes);

$mimeTypes = Tools\MimeTypesExtensions::GetMimeTypesByExtension('madness');
// NULL - means no data for given extension
var_dump($mimeTypes);

$extensions = Tools\MimeTypesExtensions::GetExtensionsByMimeType('application/msword');
// ['doc','dot'] - means mimetype `application/msword` could have two different extensions
var_dump($extensions);

$extensions = Tools\MimeTypesExtensions::GetExtensionsByMimeType('video/bmpeg');
// [''] - means file type is defined as file always without any extension
var_dump($extensions);

$extensions = Tools\MimeTypesExtensions::GetExtensionsByMimeType('something/crazy');
// NULL - means no data for given mimetype
var_dump($extensions);

Building fresh version

sh scripts/build.sh
# scripts/build.bat

Tests

sh scripts/test.sh
# scripts/test.bat