Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dfridrich/PhpMimeType
Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.
https://github.com/dfridrich/PhpMimeType
mime-type php symfony
Last synced: about 2 months ago
JSON representation
Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.
- Host: GitHub
- URL: https://github.com/dfridrich/PhpMimeType
- Owner: dfridrich
- License: mit
- Created: 2014-02-25T10:17:48.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-12-09T11:28:40.000Z (about 1 year ago)
- Last Synced: 2024-10-20T11:54:36.067Z (2 months ago)
- Topics: mime-type, php, symfony
- Language: PHP
- Homepage:
- Size: 187 KB
- Stars: 16
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PhpMimeType v3
[![Join the chat at https://gitter.im/dfridrich/PhpMimeType](https://badges.gitter.im/dfridrich/PhpMimeType.svg)](https://gitter.im/dfridrich/PhpMimeType?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/dfridrich/PhpMimeType.svg)](https://travis-ci.org/dfridrich/PhpMimeType)
[![Latest Stable Version](https://poser.pugx.org/dfridrich/php-mime-type/v/stable)](https://packagist.org/packages/dfridrich/php-mime-type)
[![Total Downloads](https://poser.pugx.org/dfridrich/php-mime-type/downloads)](https://packagist.org/packages/dfridrich/php-mime-type)
[![Monthly Downloads](https://poser.pugx.org/dfridrich/php-mime-type/d/monthly)](https://packagist.org/packages/dfridrich/php-mime-type)
[![License](https://poser.pugx.org/dfridrich/php-mime-type/license)](https://packagist.org/packages/dfridrich/php-mime-type)[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/dfridrich)
![PhpMimeType](phpmimetype.png "PhpMimeType")
Simple PHP class for guessing file mime type based on file extension with ability to use in Symfony project.
## Install
``` sh
composer require dfridrich/php-mime-type
```## Usage
### Basic usage
```php
getFileName(), $mimeType->getMimeType()).'
';
}// 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.
``` sh
composer require symfony/http-foundation
```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
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](examples/).
API documentation can be found [here](http://dfridrich.github.io/PhpMimeType/).
## Testing
``` bash
composer test
```## Credits
### Contributors
* [Dennis Fridrich](https://github.com/dfridrich)
* Nick Shek
* [Giso Stallenberg](https://github.com/gisostallenberg)
* [sml-joyo](https://github.com/sml-joyo)### Thanks to...
* [freepik.com](http://www.freepik.com) - it provided photo in logo
* [svogal](http://php.net/manual/en/function.mime-content-type.php#87856) - this guy inspired me to create this library
* [colemanw](https://gist.github.com/colemanw/9c9a12aae16a4bfe2678de86b661d922) - his gist inspired me to add FontAwesome support## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.