flysystem/mime-type-detection

此包已被废弃,不再维护。作者建议使用 league/mime-type-detection 包。

Flysystem 的 MIME 类型检测

dev-master 2020-02-25 20:59 UTC

This package is auto-updated.

Last update: 2020-08-11 21:49:42 UTC


README

Author Source Code Latest Version Software License Build Status Coverage Status Quality Score Total Downloads php 7.2+

此包提供了一个基于 finfo 的通用 MIME 类型检测接口。

用法

composer require flysystem/mime-type-detection

检测器

带有扩展回退的 Finfo

$detector = new Flysystem\MimeTypeDetection\FinfoMimeTypeDetector();

// Detect by contents, fall back to detection by extension.
$mimeType = $detector->detectMimeType('some/path.php', 'string contents');

// Detect by contents only, no extension fallback.
$mimeType = $detector->detectMimeTypeFromBuffer('string contents');

// Detect by actual file, no extension fallback.
$mimeType = $detector->detectMimeTypeFromFile('existing/path.php');

// Only detect by extension
$mimeType = $detector->detectMimeTypeFromPath('any/path.php');

仅扩展

$detector = new Flysystem\MimeTypeDetection\ExtensionMimeTypeDetector();

// Only detect by extension
$mimeType = $detector->detectMimeType('some/path.php', 'string contents');

// Always returns null
$mimeType = $detector->detectMimeTypeFromBuffer('string contents');

// Only detect by extension
$mimeType = $detector->detectMimeTypeFromFile('existing/path.php');

// Only detect by extension
$mimeType = $detector->detectMimeTypeFromPath('any/path.php');

扩展 MIME 类型查找

作为基于 finfo 的查找的回退,使用扩展映射来确定 MIME 类型。提供了一个建议的实现,该实现由 npm 包 mime-db 收集的信息生成。

提供的扩展映射

生成的

$map = new Flysystem\MimeTypeDetection\GeneratedExtensionToMimeTypeMap();

// string mime-type or NULL
$mimeType = $map->lookupMimeType('png');

空的

$map = new Flysystem\MimeTypeDetection\EmptyExtensionToMimeTypeMap();

// Always returns NULL
$mimeType = $map->lookupMimeType('png');