1 | <?php |
||
2 | |||
3 | namespace ImageMimeTypeGuesser\Detectors; |
||
4 | |||
5 | class MimeContentType extends AbstractDetector |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * Try to detect mime type of image using "mime_content_type" |
||
10 | * |
||
11 | * Like all detectors, it returns: |
||
12 | * - null (if it cannot be determined) |
||
13 | * - false (if it can be determined that this is not an image) |
||
14 | * - mime (if it is in fact an image, and type could be determined) |
||
15 | * @return mime | null | false. |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
16 | */ |
||
17 | protected function doDetect($filePath) |
||
18 | { |
||
19 | // mime_content_type supposedly used to be deprecated, but it seems it isn't anymore |
||
20 | // it may return false on failure. |
||
21 | if (function_exists('mime_content_type')) { |
||
22 | try { |
||
23 | $result = mime_content_type($filePath); |
||
24 | if ($result !== false) { |
||
25 | if (strpos($result, 'image/') === 0) { |
||
26 | return $result; |
||
27 | } else { |
||
28 | return false; |
||
29 | } |
||
30 | } |
||
31 | } catch (\Exception $e) { |
||
32 | // we are unstoppable! |
||
33 | } |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 |