mvccore/ext-tool-mimetype-extension
Composer 安装命令:
composer require 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.
关键字:
README 文档
README
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:
- IANA (http://www.iana.org/assignments/media-types/media-types.xhtml)
- APACHE (http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types)
- NGINX (http://hg.nginx.org/nginx/raw-file/default/conf/mime.types)
- custom definitions in
./custom-mimes.json
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
统计信息
- 总下载量: 385
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 1
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2018-08-24