From 04120bc832a2adddf779787ec44d1e68d1a087d5 Mon Sep 17 00:00:00 2001 From: wapmorgan Date: Sat, 4 Mar 2017 00:13:01 +0300 Subject: [PATCH] Add mimetype info --- README.md | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4e7107f..73b88f3 100644 --- a/README.md +++ b/README.md @@ -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: