Skip to content

🎯 PHP MIME Types Guesser and extension mapping.

License

Notifications You must be signed in to change notification settings

PrisisForks/mimetypes

 
 

Repository files navigation

MIME Types

PHP MIME Types Guesser and extension mapper.

built with jshttp/mime-db.

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 mapping.

Installation

composer require narrowspark/mimetypes

Use

This mime type guesser has support for all OS supported guesser.

<?php
    use Narrowspark\MimeType\MimeType;
    
    // You can register custom guessers by calling the register() method
    MimeType::register('CustomGuesser');

    return MimeType::guess('image.gif'); // returns image/gif

You looking for the full mime type array? Just use:

<?php
    use Narrowspark\MimeType\MimeTypesList;

    return MimeTypesList::MIMES; // returns array

If you like to use the build in php mime type guesser, just use:

<?php
    use Narrowspark\MimeType\MimeTypeFileInfoGuesser;
    use Narrowspark\MimeType\MimeTypeFileBinaryGuesser;
    use Narrowspark\MimeType\MimeTypeExtensionGuesser;
    use Narrowspark\MimeType\MimeTypeFileExtensionGuesser;

    
    // Inspecting the file using finfo and relies on magic db files.
    return MimeTypeFileInfoGuesser::guess('image.gif'); // returns image/gif
    // Inspecting the file using file -b --mime
    return MimeTypeFileBinaryGuesser::guess('image.gif'); // returns image/gif
    // Inspecting the extension using mime type list
    return MimeTypeExtensionGuesser::guess('gif'); // returns image/gif
    // Inspecting the file using mime type list
    return MimeTypeFileExtensionGuesser::guess('image.gif'); // returns image/gif

Contributing

If you would like to help take a look at the list of issues and check our Contributing guild.

Note: Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

License

The Narrowspark mimetypes is open-sourced software licensed under the MIT license

About

🎯 PHP MIME Types Guesser and extension mapping.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 99.2%
  • Shell 0.8%