pear / mime_type
检测文件的 MIME 类型
v1.4.1
2015-11-04 19:57 UTC
Requires
- pear/pear-core-minimal: ^1.9.5
Requires (Dev)
Suggests
- pear/system_command: Install optionally via your project's composer.json
This package is auto-updated.
Last update: 2024-09-16 19:00:33 UTC
README
PHP 库,用于检测、解析和使用 MIME 类型。
特性
- 解析 MIME 类型
- 支持完整的 RFC 2045 规范
- 提供许多实用函数,用于处理和确定类型信息
- 大多数函数可以静态调用
- 自动检测文件的 MIME 类型,可以使用
fileinfo
扩展、mime_magic
扩展、'file' 命令或内置的文件扩展名映射列表
安装
PEAR
$ pear install MIME_Type
Composer
$ composer require pear/mime_type
使用方法
请参阅 docs/examples/
目录中的示例和 官方文档。
检测文件的 MIME 类型
<?php require_once 'MIME/Type.php'; $type = MIME_Type::autoDetect('/path/to/file'); if (PEAR::isError($type)) { echo 'Error: ' . $type->getMessage() . "\n"; exit(1); } else { echo 'MIME type: ' . $type . "\n"; } ?>
链接
- 主页
- http://pear.php.net/package/MIME_Type
- 错误跟踪器
- http://pear.php.net/bugs/search.php?cmd=display&package_name[]=MIME_Type
- 文档
- http://pear.php.net/package/MIME_Type/docs
- 单元测试状态
https://travis-ci.org/pear/MIME_Type
开发
更新扩展映射
可以从 Apache 的源代码仓库更新内置的扩展到类型的映射列表
$ ./scripts/update-mimelist.php ... 785 new, 28 updated, 168 same, 5 own, 986 total Code updated
现在将更改文件 MIME/Type/Extension.php
。