All Projects → adrienrn → php-mimetyper

adrienrn / php-mimetyper

Licence: MIT license
PHP mime type and extension mapping library: built with jshttp/mime-db, compatible with Symfony and Laravel

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-mimetyper

mimetypes
Erlang MIME types library
Stars: ✭ 77 (+266.67%)
Mutual labels:  mime-types
Mime Types
The ultimate javascript content-type utility.
Stars: ✭ 865 (+4019.05%)
Mutual labels:  mime-types
Swime
🗂 Swift MIME type checking based on magic bytes
Stars: ✭ 119 (+466.67%)
Mutual labels:  mime-types
ruby-magic
Simple interface to libmagic for Ruby Programming Language
Stars: ✭ 23 (+9.52%)
Mutual labels:  mime-types
Mime Db
Media Type Database
Stars: ✭ 612 (+2814.29%)
Mutual labels:  mime-types
Mime
Map filenames to MIME types
Stars: ✭ 21 (+0%)
Mutual labels:  mime-types
MimeTypesMap
Simple dictionary provides a few methods to lookup mime type/extension, generated From Apache's mime.types.
Stars: ✭ 25 (+19.05%)
Mutual labels:  mime-types
Yagmail
Send email in Python conveniently for gmail using yagmail
Stars: ✭ 2,169 (+10228.57%)
Mutual labels:  mime-types
Mime
Shared MIME-info database in D programming language
Stars: ✭ 7 (-66.67%)
Mutual labels:  mime-types
Mime
The Hoa\Mime library.
Stars: ✭ 100 (+376.19%)
Mutual labels:  mime-types
Filepicker
🔥🔥🔥Android文件、图片选择器,可按文件夹查找,文件类型查找,支持自定义相机
Stars: ✭ 265 (+1161.9%)
Mutual labels:  mime-types
Mimetype
A fast golang library for MIME type and file extension detection, based on magic numbers
Stars: ✭ 452 (+2052.38%)
Mutual labels:  mime-types
Mog
A different take on the UNIX tool cat
Stars: ✭ 62 (+195.24%)
Mutual labels:  mime-types
Mime
.NET wrapper for libmagic
Stars: ✭ 51 (+142.86%)
Mutual labels:  mime-types
Apaxy
a simple, customisable theme for your apache directory listing
Stars: ✭ 1,672 (+7861.9%)
Mutual labels:  mime-types
transmat
Share data beyond the browser boundaries. Enable users to transfer data to external apps, and open your webapp to receive external data.
Stars: ✭ 453 (+2057.14%)
Mutual labels:  mime-types
Sixarm ruby magic number type
SixArm.com » Ruby » MagicNumberType infers a data type from the data's leading bytes
Stars: ✭ 13 (-38.1%)
Mutual labels:  mime-types
mimesniff
MIME Sniffing Standard
Stars: ✭ 89 (+323.81%)
Mutual labels:  mime-types
Fileio.jl
Main Package for IO, loading all different kind of files
Stars: ✭ 133 (+533.33%)
Mutual labels:  mime-types
Filetype
Fast, dependency-free, small Go package to infer the binary file type based on the magic numbers signature
Stars: ✭ 1,278 (+5985.71%)
Mutual labels:  mime-types

php-mimetyper

PHP mime type and extension mapping library: built with jshttp/mime-db, compatible with Symfony and Laravel.

use MimeTyper\Repository\MimeDbRepository;

$mimeRepository = new MimeDbRepository();

$mimeRepository->findExtensions("image/jpeg"); // ["jpeg","jpg","jpe"]
$mimeRepository->findExtension("image/jpeg"); // "jpeg"

$mimeRepository->findType("html"); // "html"
$mimeRepository->findType("js"); // 'application/javascript'

The most complete and up-to-date mime type mapping for PHP!

The goal is to provide a complete and up-to-date mime types mapping for PHP and build a comprehensive and simple interface for PHP. This package is heavily inspired from dflydev work and extends it.

Mime types mapping, the right way.

This library uses jshttp/mime-db as its default mapping which aggregates data from multiple sources and creates a single db.json making it the most complete two ways mapping, from mime to extension and extension to mime types too.

Custom mime types and custom repositories

Some custom types (aliases really) are maintained locally too, in the same JSON format as jshttp/mime-db.

use MimeTyper\Repository\ExtendedRepository;

$mimeRepostory = new ExtendedRepository();

$mimeRepository->findExtensions("text/x-php"); // ["php", "php2", "php3", "php4", "php5"]

$mimeRepository->findTypes("php"); // ["text/x-php", "application/x-php", "text/php", "application/php", "application/x-httpd-php"]
$mimeRepository->findType("php"); // "text/x-php"

The reason to maintain aliases locally helps with overall compatibility between mime type guessing methods. Tools detecting mime types don't always return standard mime type or the standard mime type does not exist. All of those custom mime types might be added to jshttp/mime-db custom types in the end.

Example: Debian will detect a PHP file as text/x-php while browsers will send application/x-httpd-php. It goes the same with files such as Javascript (application/javascript vs text/javascript) or Microsoft Office / Libre Office files.

Don't hesitate to make a pull request to discuss this.

Mime types for Symfony and Laravel

This library is compatible with your Symfony or Laravel app to enjoy the completeness of the mapping.

Use the ExtraMimeTypeExtensionGuesser as a bridge class between Symfony ExtensionGuesser and this package RepositoryInterface.

use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;

use MimeTyper\Repository\ExtendedRepository;
use MimeTyper\Symfony\ExtraMimeTypeExtensionGuesser;

$symfonyGuesser = ExtensionGuesser::getInstance();
$extraGuesser = new ExtraMimeTypeExtensionGuesser(
    new ExtendedRepository()
);
$symfonyGuesser->register($extraGuesser);

This example uses the ExtendedRepository (mime-db and local custom mime types), you can use the default MimeDbRepository, implement your own or use a CompositeRepository to aggregate multiple repostories.

Safe detection of mime type in PHP

Before mapping type to extension or extension to type, you need to be able to properly detect the mime type of a file.

For security reasons, do not trust browsers, eg $_FILES['your_file']['type'], when it comes to detect the mime type of a file.

To safely detect the mime type of a file, . Symfony is giving a great example with their MimeTypeGuesser implementation of:

It all ends up inspecting the file using finfo and relies on magic db files. PHP will use its own magic db or your system magic db depending on your environement.

Other PHP libraries for mime types

  • dflydev/dflydev-apache-mime-types

    Uses mime.types Apache file, comprehensive api. As stated before, php-mimetyper is heavily inspired by this, extending it to be a bit more complete using an external mapping and a wider interface.

  • symfony/http-foundation

    Symfony provides a nice interface for guessing mime types and extensions but uses only a local mapping based on Apache registry, see above to bridge it to this package.

  • davidpersson/mm

    Library for media processing and mime type and extension guessing. Uses FreeDesktop magic.db file for the latter.

  • Hoa/Mime

    The Hoa package to deal with mime types. Uses mime.types Apache file (local fallback) and relies on static methods.

  • karwana/php-mime

    Uses mime.types Apache file and finfo, requires PHP >=5.4.

  • PEAR/MIME_Type

    Detect the mime type of a file: uses internally finfo_file, mime_content_type or file command to guess the mime type.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].