<commit_before># MIME #

MIME type and file extension utilities for PHP. Powered by [`finfo`](http://php.net/manual/en/book.fileinfo.php) and the Apache-provided public domain [mime.types](https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types) map of media types to unique file extension(s).

## Examples ##

Get the MIME type of an uploaded file. The original file name is used before falling back to running `finfo` if the file has no extension or if the extension is unlisted.

```php
use Karwana\Mime;

$mime_type = Mime::guessType($_FILES['my_file']['tmp_name'], $_FILES['my_file']['name']);

// Now get the canonical extension.
$extension = Mime::getExtensionForType(mime_type);
```

Add an extension to an extensionless file.

```php
file_path = 'path/to/extensionless_file';

rename($file_path, $file_path . '.' . Mime::guessExtension($file_path));
```

## Development ##

Run tests using `$ vendor/bin/phing test`.

Use the provided script to update the MIME type list to the latest version from Apache's tracker.<commit_msg>Add travis-ci badge<commit_after># MIME #

[![Build Status](https://travis-ci.org/karwana/php-mime.svg?branch=master)](https://travis-ci.org/karwana/php-mime)

MIME type and file extension utilities for PHP. Powered by [`finfo`](http://php.net/manual/en/book.fileinfo.php) and the Apache-provided public domain [mime.types](https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types) map of media types to unique file extension(s).

## Examples ##

Get the MIME type of an uploaded file. The original file name is used before falling back to running `finfo` if the file has no extension or if the extension is unlisted.

```php
use Karwana\Mime;

$mime_type = Mime::guessType($_FILES['my_file']['tmp_name'], $_FILES['my_file']['name']);

// Now get the canonical extension.
$extension = Mime::getExtensionForType(mime_type);
```

Add an extension to an extensionless file.

```php
file_path = 'path/to/extensionless_file';

rename($file_path, $file_path . '.' . Mime::guessExtension($file_path));
```

## Development ##

Run tests using `$ vendor/bin/phing test`.

Use the provided script to update the MIME type list to the latest version from Apache's tracker.
{'fraction_non_alphanumeric': 0.13605747642568478, 'fraction_numerical': 0.0, 'mean_word_length': 4.957219251336898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6357030', 'n_tokens_mistral': 736, 'n_tokens_neox': 701, 'n_words': 221}