Skip to content
This repository has been archived by the owner on Aug 9, 2020. It is now read-only.

flysystemphp/mime-type-detection

Repository files navigation

Flysystem Mime Type Detection

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

This package supplies a generic mime-type detection interface with a finfo based implementation.

Usage

composer require flysystem/mime-type-detection

Detectors

Finfo with extension fallback:

$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');

Extension only:

$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');

Extension mime-type lookup

As a fallback for finfo based lookup, an extension map is used to determine the mime-type. There is an advised implementation shipped, which is generated from information collected by the npm package mime-db.

Provided extension maps

Generated:

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

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

Empty:

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

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages