Skip to content

Commit

Permalink
Add mimetype info
Browse files Browse the repository at this point in the history
  • Loading branch information
wapmorgan committed Mar 3, 2017
1 parent b745f40 commit 04120bc
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,38 @@ Files type detector based on file name extension or file content (binary content

# Usage

### How to detect by file name
## File Type detection

- Detection by filename: `detectByFilename(...filename...)`
- Detection by content: `detectByContent(...filename...)`

Example:

```php
$type = wapmorgan\FileTypeDetector\Detector::detectByFilename(...filename...);
```
`$type` will contain file type as an array like this:
```
array(
Detector::AUDIO,
Detector::MP3
)
$type = wapmorgan\FileTypeDetector\Detector::detectByFilename($filename);

// $type will contain file type as an array like this:
// array(
// Detector::AUDIO,
// Detector::MP3
// )
// In case of failure it will contain `false`.


$type = wapmorgan\FileTypeDetector\Detector::detectByContent($filename);
// or
$type = wapmorgan\FileTypeDetector\Detector::detectByContent($stream);
```
In case of failure it will contain `false`.

### How to detect by file content
## Mimetype generation

To use correct mimetype for file there is `getMimeType($type)` function.

```php
$type = wapmorgan\FileTypeDetector\Detector::detectByContent(...filename...);
$mime = wapmorgan\FileTypeDetector\Detector::getMimeType($type[1]);
// or
$type = wapmorgan\FileTypeDetector\Detector::detectByContent(...stream...);
$mime = wapmorgan\FileTypeDetector\Detector::getMimeType(wapmorgan\FileTypeDetector\Detector::MP3);
```
`$type` can have the same values as described above.

# Installation
Install package via composer:
Expand Down

0 comments on commit 04120bc

Please sign in to comment.