RFC 4288 parser, cacher, and abstraction library for PHP.
Find a file
2024-10-27 11:52:32 +00:00
src initial commit 2024-10-27 12:37:08 +01:00
.gitignore initial commit 2024-10-27 12:37:08 +01:00
composer.json initial commit 2024-10-27 12:37:08 +01:00
LICENSE initial commit 2024-10-27 12:37:08 +01:00
README.md doc(feat): add README 2024-10-27 11:52:32 +00:00

MIME-type parser and abstraction library for PHP

Resolve MIME-types from file extensions and vice versa by passing a URL to an RFC 4288-compatible source to this library.

use vlw\MimeTypes\MimeTypes;

$mime = new MimeTypes("https://raw.githubusercontent.com/apache/httpd/refs/heads/trunk/docs/conf/mime.types");

// From string
$mime->get_ext_from_type("image/webp"); // "webp"
$mime->get_type_from_ext("webp"); // "image/webp"

// From pathname
$mime->get_ext_from_file("path/to/file.webp") // "webp"
$mime->get_type_from_file("path/to/file.webp) // "image/webp"

Installation

composer require vlw/mime-types

Use

use vlw\MimeTypes\MimeTypes;

$mime = new MimeTypes(string $url);

Defaults to Apache's mime.types file from GitHub if no value is provided to $url