定制 blobfolio/blob-mimes 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Features
  2. Requirements
  3. Installation
  4. Reference
  5. License

 

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 return TRUE if 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

Bitcoin QR 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 blobfolio/blob-mimes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.82k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 17
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: WTFPL
  • 更新时间: 2017-01-15