2017 © Pedro Peláez
 

library mimetype

PHP library for obtain headers MIME.

image

josantonius/mimetype

PHP library for obtain headers MIME.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 10 Versions
  • 26 % Grown

The README.md

PHP MimeType library

Latest Stable Version License Total Downloads CI CodeCov PSR1 PSR4 PSR12, (*1)

PHP library to get MIME types from extensions., (*2)

The original concept of my project, linking a single mimetype to a file extension, has been found to be insufficient in accurately reflecting the many-to-one relationships that exist in real-world use-cases. In practice, multiple file extensions often correspond to a single mimetype, rendering my existing design approach suboptimal., (*3)

Given these insights, I've decided to archive this repository. I recommend those interested to look at the approach taken by the repository patrickmccallum/mimetype-io. This project adopts a more nuanced perspective, effectively managing mimetypes by acknowledging the possibility of multiple extensions corresponding to a single mimetype. I believe this is a more promising approach for managing mimetypes moving forward., (*4)

Requirements

  • Operating System: Linux | Windows., (*5)

  • PHP versions: 8.0 | 8.1 | 8.2., (*6)

Installation

The preferred way to install this extension is through Composer., (*7)

To install PHP MimeType library, simply:, (*8)

composer require josantonius/mime-type

The previous command will only install the necessary files, if you prefer to download the entire source code you can use:, (*9)

composer require josantonius/mime-type --prefer-source

You can also clone the complete repository with Git:, (*10)

git clone https://github.com/josantonius/php-mime-type.git

Available Classes

MimeType

Josantonius\MimeType\MimeType, (*11)

Get array with all MIME types:, (*12)

public function all(): array;

Get file extension from MIME type:, (*13)

public function getExtension(string $mimeType): string|null;

Get MIME type from file extension:, (*14)

public function getMime(string $extension): string|null;

MimeTypeCollection

Josantonius\MimeType\MimeTypeCollection, (*15)

Get array with all MIME types:, (*16)

public static function all(): array;

Get file extension from MIME type:, (*17)

public static function getExtension(string $mimeType): string|null;

Get MIME type from file extension:, (*18)

public static function getMime(string $extension): string|null;

Usage

Example of use for this library:, (*19)

Get array with all MIME types

use Josantonius\MimeType\MimeType;

$mimeType = new MimeType();

$mimeType->all();
use Josantonius\MimeType\MimeTypeCollection;

MimeTypeCollection::all();

Result:, (*20)

[
    [".123"]=> "application/vnd.lotus-1-2-3"
    [".3dml"]=> "text/vnd.in3d.3dml"
    [".3g2"]=> "video/3gpp2"
    [".3gp"]=> "video/3gpp"
    [".7z"]=> "application/x-7z-compressed"
    [".aab"]=> "application/x-authorware-bin"
    [".aac"]=> "audio/x-aac"
    [".aam"]=> "application/x-authorware-map"
    [".aas"]=> "application/x-authorware-seg"
    [".abw"]=> "application/x-abiword"
    (...)
]

Get file extension from MIME type

use Josantonius\MimeType\MimeType;

$mimeType = new MimeType();

$mimeType->getExtension('text/html'); // .html
use Josantonius\MimeType\MimeTypeCollection;

MimeTypeCollection::getExtension('application/zip'); // .zip

Get MIME type from file extension

use Josantonius\MimeType\MimeType;

$mimeType = new MimeType();

$mimeType->getMime('.tar'); // application/x-tar

// The dot can be omitted:

$mimeType->getMime('mp4'); // video/mp4
use Josantonius\MimeType\MimeTypeCollection;

MimeTypeCollection::getMime('.json'); // application/json

Tests

To run tests you just need composer and to execute the following:, (*21)

git clone https://github.com/josantonius/php-mime-type.git
cd PHP-MimeType
composer install

Run unit tests with PHPUnit:, (*22)

composer phpunit

Run code standard tests with PHPCS:, (*23)

composer phpcs

Run PHP Mess Detector tests to detect inconsistencies in code style:, (*24)

composer phpmd

Run all previous tests:, (*25)

composer tests

TODO

  • [ ] Add new feature
  • [ ] Improve tests
  • [ ] Improve documentation
  • [ ] Improve English translation in the README file
  • [ ] Refactor code for disabled code style rules (see phpmd.xml and phpcs.xml)

Changelog

Detailed changes for each release are documented in the release notes., (*26)

Contribution

Please make sure to read the Contributing Guide, before making a pull request, start a discussion or report a issue., (*27)

Thanks to all contributors! :heart:, (*28)

If this project helps you to reduce your development time, you can sponsor me to support my open source work :blush:, (*29)

License

This repository is licensed under the MIT License., (*30)

Copyright © 2016-2023, Josantonius, (*31)

The Versions

06/01 2018

dev-master

9999999-dev

PHP library for obtain headers MIME.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

mime php hhvm audio video mimetype multipart aplication

06/01 2018

1.1.7

1.1.7.0

PHP library for obtain headers MIME.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

mime php hhvm audio video mimetype multipart aplication

12/11 2017

1.1.6

1.1.6.0

PHP library for obtain headers MIME.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

mime php hhvm audio video mimetype multipart aplication

02/11 2017

1.1.5

1.1.5.0

PHP library for obtain headers MIME.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

mime php hhvm audio video mimetype multipart aplication

19/10 2017

1.1.4

1.1.4.0

PHP library for obtain headers MIME.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

mime php hhvm audio video mimetype multipart aplication

14/10 2017

1.1.3

1.1.3.0

PHP library for obtain headers MIME.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

mime php hhvm audio video mimetype multipart aplication

18/07 2017

1.1.2

1.1.2.0

PHP library for obtain headers MIME.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

mime php hhvm audio video mimetype multipart aplication

18/03 2017

1.1.1

1.1.1.0

PHP library for obtain headers MIME.

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

mime php hhvm audio video mimetype multipart aplication

31/01 2017

1.1.0

1.1.0.0

PHP library for obtain headers MIME.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

mime php hhvm audio video mimetype multipart aplication

28/01 2017

1.0.0

1.0.0.0

PHP library for obtain headers MIME.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

mime php hhvm audio video mimetype multipart aplication