2017 © Pedro Peláez
 

library php-mime-type

Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.

image

dfridrich/php-mime-type

Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.

  • Friday, January 26, 2018
  • by dfridrich
  • Repository
  • 2 Watchers
  • 9 Stars
  • 48,452 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 10 Versions
  • 9 % Grown

The README.md

PhpMimeType v3

Join the chat at https://gitter.im/dfridrich/PhpMimeType Build Status Latest Stable Version Total Downloads Monthly Downloads License, (*1)

"Buy Me A Coffee", (*2)

PhpMimeType, (*3)

Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project., (*4)

Install

``` sh composer require dfridrich/php-mime-type, (*5)


## Usage ### Basic usage ```php <?php // from string, can be used on non-existing files echo \Defr\PhpMimeType\MimeType::get('index.php'); // outputs text/html // from SplFileInfo echo \Defr\PhpMimeType\MimeType::get(new \SplFileInfo('Video.avi')); // outputs application/octet-stream // from SplFileObject echo \Defr\PhpMimeType\MimeType::get(new \SplFileObject('Image.JPEG')); // outputs image/jpeg // from string echo \Defr\PhpMimeType\MimeType::get('someStrange.extension'); // outputs application/octet-stream // Multiple files $files = ['index.php', new \SplFileInfo('Video.avi'), new \SplFileObject('example.php')]; /** @var \Defr\PhpMimeType\MimeTypeInfo[] $mimeTypes */ $mimeTypes = \Defr\PhpMimeType\MimeType::multiple($files); foreach ($mimeTypes as $mimeType) { echo sprintf('File "%s" is mime type "%s"', $mimeType->getFileName(), $mimeType->getMimeType()).'<br>'; } // Guess FontAwesome icon echo \Defr\PhpMimeType\MimeType::getFontAwesomeIcon('test.pdf'); // fa fa-file-pdf-o // ...with fixed width icon echo \Defr\PhpMimeType\MimeType::getFontAwesomeIcon('test.pdf', true); // fa fa-file-pdf-o fa-fw

Symfony response

If you want to use Symfony response feature, install HTTP Foundation package too., (*6)

``` sh composer require symfony/http-foundation, (*7)


Just pass the file name or SPL object to response method and you will get Symfony\Component\HttpFoundation\Response object. Disposition is **attachment** by default, you can chage it to **inline** or use Symfony ResponseHeaderBag's constants DISPOSITION_ATTACHMENT or DISPOSITION_INLINE. ```php <?php // Return response to download this file as attachment (default) $response = \Defr\PhpMimeType\MimeType::response(__FILE__); $response->send(); // Return response to download this file inline $response = \Defr\PhpMimeType\MimeType::response(__FILE__, \Symfony\Component\HttpFoundation\ResponseHeaderBag::DISPOSITION_INLINE); $response->send(); // You can use FileAsResponse object too (and own file name) $response = \Defr\PhpMimeType\FileAsResponse::get(__FILE__, null, "my-own-file-name.txt"); $response->send(); // Or directly send it to browser $response = \Defr\PhpMimeType\FileAsResponse::send(__FILE__);

More examples and documentation

See more examples., (*8)

API documentation can be found here., (*9)

Testing

bash composer test, (*10)

Credits

Contributors

Thanks to...

  • freepik.com - it provided photo in logo
  • svogal - this guy inspired me to create this library
  • colemanw - his gist inspired me to add FontAwesome support

License

The MIT License (MIT). Please see License File for more information., (*11)

The Versions

26/01 2018

dev-master

9999999-dev https://github.com/dfridrich/PhpMimeType

Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.

  Sources   Download

MIT

The Requires

  • php ^5.6|^7.0

 

The Development Requires

php mimetype

26/01 2018

v2.0.3

2.0.3.0 https://github.com/dfridrich/PhpMimeType

Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.

  Sources   Download

MIT

The Requires

  • php ^5.6|^7.0

 

The Development Requires

php mimetype

26/01 2018

v2.0.4

2.0.4.0 https://github.com/dfridrich/PhpMimeType

Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.

  Sources   Download

MIT

The Requires

  • php ^5.6|^7.0

 

The Development Requires

php mimetype

30/10 2017

v2.0.2

2.0.2.0 https://github.com/dfridrich/PhpMimeType

Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.

  Sources   Download

MIT

The Requires

  • php ^5.6|^7.0

 

The Development Requires

php mimetype

31/05 2017

v2.0.1

2.0.1.0 https://github.com/dfridrich/PhpMimeType

Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.

  Sources   Download

MIT

The Requires

  • php ^5.6|^7.0

 

The Development Requires

php mimetype

02/05 2016

v2.0.0

2.0.0.0 https://github.com/dfridrich/PhpMimeType

Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.

  Sources   Download

MIT

The Requires

  • php ^5.6|^7.0

 

The Development Requires

php mimetype

06/04 2016

v2.0.0-alpha

2.0.0.0-alpha https://github.com/dfridrich/PhpMimeType

Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.

  Sources   Download

MIT

The Requires

  • php ^5.6|^7.0

 

The Development Requires

php mimetype

06/04 2016

v1.0.1

1.0.1.0 https://github.com/dfridrich/PhpMimeType

Simple PHP class for guessing file mime type based on file extension.

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

php mimetype

09/09 2015

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/dfridrich/PhpMimeType

Simple class for guessing PHP Mime Type.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php mimetype

08/09 2015

v1.0

1.0.0.0 https://github.com/dfridrich/PhpMimeType

Simple class for guessing PHP Mime Type.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php mimetype