pear / mime_type
Detect the MIME Type of a file
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-04-16 18:10:34 UTC
README
PHP library to detect, parse and work with MIME types.
Features:
- Parse MIME types
- Supports full RFC 2045 specification
- Many utility functions for working with and determining info about types
- Most functions can be called statically
- Autodetect a file's mime-type, either with
fileinfo
extension,mime_magic
extension, the 'file' command or an in-built file extension mapping list
Installation
PEAR
$ pear install MIME_Type
Composer
$ composer require pear/mime_type
Usage
See the examples in the docs/examples/
directory and the official documentation.
Detecting a file's MIME type
<?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";
}
?>
Links
- Homepage
- Bug tracker
http://pear.php.net/bugs/search.php?cmd=display&package_name[]=MIME_Type
- Documentation
- Unit test status
Development
Updating extension mapping
The built-in extension-to-type mapping list can be updated from apache's source code repository:
$ ./scripts/update-mimelist.php
...
785 new, 28 updated, 168 same, 5 own, 986 total
Code updated
The file MIME/Type/Extension.php
will be changed now.