cosmicvelocity/media-types
Composer 安装命令:
composer require cosmicvelocity/media-types
包简介
Detect the Media Type (MIME Type) of a file or extentions.
README 文档
README
A PHP library for handling media types.
- Supports the RFC 6838 specification.
- MIME type character string analysis can be performed.
- Supports automatic detection from filename with built-in mapping list.
- Supports automatic detection by Fileinfo extension.
Installation
If composer is used, it can be introduced by adding the following description.
"require": {
"cosmicvelocity/media-types": ">=1.0"
}
How to use
-
When detecting from file name.
$mediaTypes = new PhpArrayMediaTypes(); $mediaType = $mediaTypes->getMediaType('sample.txt'); $mediaType->getType(); // text -
To detect from your own mapping.
$mediaTypes = new PhpArrayMediaTypes([ 'hoge' => 'application/prs.hoge+xml' ]); $mediaType = $mediaTypes->getMediaType('sample.hoge'); $mediaType->getType(); // application $mediaType->getSubType(); // prs.hoge+xml $mediaType->getTree(); // prs $mediaType->getSuffix(); // xml -
When analyzing MIME type.
$mediaType = MediaType::fromMime('application/calendar+json; charset=utf-8'); $mediaType->getType(); // application $mediaType->getSubType(); // calendar+json $mediaType->getSuffix(); // json $mediaType->getParameter('charset')->getValue(); // utf-8 -
When detecting from a file.
$mediaType = MediaType::fromFile('sample.json'); $mediaType->getType(); // text $mediaType->getSubType(); // plain
统计信息
- 总下载量: 39
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2017-11-28