| @@ 309-324 (lines=16) @@ | ||
| 306 | * @throws Exception if finfo_open() method doesn't exists |
|
| 307 | * |
|
| 308 | */ |
|
| 309 | private static function mime($file){ |
|
| 310 | ||
| 311 | if(!file_exists($file["tmp_name"])){ |
|
| 312 | return false; |
|
| 313 | } |
|
| 314 | if(!function_exists('finfo_open')) { |
|
| 315 | throw new Exception("Function finfo_open() doesn't exist"); |
|
| 316 | } |
|
| 317 | ||
| 318 | $finfo_open = finfo_open(FILEINFO_MIME_TYPE); |
|
| 319 | $finfo_file = finfo_file($finfo_open, $file["tmp_name"]); |
|
| 320 | finfo_close($finfo_open); |
|
| 321 | ||
| 322 | list($mime) = explode(';', $finfo_file); |
|
| 323 | return $mime; |
|
| 324 | } |
|
| 325 | ||
| 326 | /** |
|
| 327 | * get hashed file name, and Optionally provided by an id |
|
| @@ 624-641 (lines=18) @@ | ||
| 621 | * @throws Exception if finfo_open() doesn't exists |
|
| 622 | * @return bool |
|
| 623 | */ |
|
| 624 | private function mimeType($file, $mimeTypes){ |
|
| 625 | ||
| 626 | if(!file_exists($file["tmp_name"])){ |
|
| 627 | return false; |
|
| 628 | } |
|
| 629 | if(!function_exists('finfo_open')) { |
|
| 630 | throw new Exception("Function finfo_open() doesn't exist"); |
|
| 631 | } |
|
| 632 | ||
| 633 | $finfo_open = finfo_open(FILEINFO_MIME_TYPE); |
|
| 634 | $finfo_file = finfo_file($finfo_open, $file["tmp_name"]); |
|
| 635 | finfo_close($finfo_open); |
|
| 636 | ||
| 637 | list($mime) = explode(';', $finfo_file); |
|
| 638 | ||
| 639 | // in case of zip file it returns application/octet-stream |
|
| 640 | return in_array($mime, $mimeTypes, true); |
|
| 641 | } |
|
| 642 | ||
| 643 | /** |
|
| 644 | * validate file extension returned from pathinfo() Vs mapped mime type to extension |
|