blobfolio/blob-mimes
最新稳定版本:8.0.0
Composer 安装命令:
composer require blobfolio/blob-mimes
包简介
A comprehensive MIME and file extension tool for PHP.
关键字:
README 文档
README
DEPRECATED: This project is no longer actively maintained. Please see Righteous MIMEs instead.
A comprehensive MIME and file extension tool for PHP. Finally!
Table of Contents
Features
It should be simple, but MIME types and file extensions are wildly inconsistent. Attempting to derive and/or correct that information when, e.g. verifying a file upload, is a nightmare in any programming language.
blob-mimes is a PHP library with a comprehensive MIME/ext database and simple helpers to access that information in a variety of ways:
- Pull MIME information based on a file name or extension;
- Pull file extensions for a given MIME type;
- Pull MIME information from a local file and verify its extension matches the actual content;
The database is compiled from the following sources:
Requirements
blob-mimes requires PHP 7.0+ with the following modules:
- BCMath
- DOM
- Fileinfo
- Filter
- JSON
- MBString
- SimpleXML
UTF-8 is used for all string encoding. This could create conflicts on environments using something else.
The build script additionally requires cURL.
Installation
Install via Composer:
composer require "blobfolio/blob-mimes:dev-master"
Reference
check_ext_and_mime()
Verify that a file extension and MIME type belong together. Because technology is always evolving and the MIME standard is always changing, this will consider some/thing and some/x-thing equivalent.
Arguments
- (string) File extension
- (string) MIME type
- (bool) (optional) Soft pass. If
TRUE, the check will returnTRUEif it lacks information about either the extension or MIME type.
Returns
Returns TRUE or FALSE.
Example
$foo = blobfolio\mimes\mimes::check_ext_and_mime('jpeg', 'image/jpeg'); //TRUE $foo = blobfolio\mimes\mimes::check_ext_and_mime('jpeg', 'image/gif'); //FALSE
finfo()
Pull path and type information for a file, using its name and/or content. If it is determined that the file is incorrectly named, alternative names with the correct file extension(s) are suggested.
Arguments
- (string) Path
- (string) (optional) Nice name. If provided, the nice name will be treated as the filename. This can be useful if passing a temporary upload, for example. Default:
NULL
Returns
Returns all file information that can be derived according to the format below.
Example
print_r(blobfolio\mimes\mimes::finfo('../wp/img/blobfolio.svg')); /* array( [dirname] => /var/www/blob-common/wp/img [basename] => blobfolio.svg [extension] => svg [filename] => blobfolio [path] => /var/www/blob-common/wp/img/blobfolio.svg [mime] => image/svg+xml [suggested_filename] => array() ) */
get_extension()
Retrieve information about a file extension.
Arguments
- (string) File extension
Returns
Returns the information or FALSE. Note: The first MIME entry will always be the official (or most conventional) media type.
print_r(blobfolio\mimes\mimes::get_extension('jpeg')); /* array( [ext] => jpeg [mime] => array( 0 => image/jpeg 1 => image/pjpeg ) ) */
get_extensions()
Retrieve information about all known file extensions.
Arguments
N/A
Returns
Returns a MIME database organized by extension.
get_mime()
Retrieve information about a MIME type.
Arguments
- (string) MIME type
Returns
Returns the information or FALSE.
Example
print_r(blobfolio\mimes\mimes::get_mime('image/jpeg')); /* array( [mime] => image/jpeg [ext] => array( 0 => jpeg 1 => jpg 2 => jpe ) [source] => array( 0 => Apache 1 => Nginx 2 => freedesktop.org ) ) */
get_mimes()
Retrieve information about all known MIME types.
Arguments
N/A
Returns
Returns a MIME database organized by type. Note: The first extension should be the most common for the type.
License
Copyright © 2018 Blobfolio, LLC <hello@blobfolio.com>
This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
Donations
| If you have found this work useful and would like to contribute financially, Bitcoin tips are always welcome! 1Af56Nxauv8M1ChyQxtBe1yvdp2jtaB1GF |
blobfolio/blob-mimes 适用场景与选型建议
blobfolio/blob-mimes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.82k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2017 年 01 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extensions」 「files」 「mimes」 「suffix」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blobfolio/blob-mimes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blobfolio/blob-mimes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blobfolio/blob-mimes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An HTML5 upload field for the CMS and frontend forms.
A collection of helpers for PHPUnit to ease testing Tarantool libraries.
A very simple yet useful helper class to handle PHP file uploads.
The flysystem adapter for yandex disk rest api.
Register more Twig filters for your OctoberCMS templates
Bundle for Doctrine enumerations extension for Postgres
统计信息
- 总下载量: 5.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 17
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: WTFPL
- 更新时间: 2017-01-15