kohana / ohanzee-helpers

Other
56 stars 10 forks source link

File: mistakes) #9

Closed WinterSilence closed 9 years ago

WinterSilence commented 10 years ago

Better move "mime" methods into separate class Mime. Also, it will reduce method names.

File::mime():

if ($file = getimagesize($filename)) {
    if (!empty($file['mime'])) {
        return $file['mime'];
    }
}

faster than

$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
if (preg_match('/^(?:jpe?g|png|[gt]if|bmp|swf)$/', $extension)) {
    $file = getimagesize($filename);
    if (!empty($file['mime'])) {
        return $file['mime'];
    }
}

Also, in_array() faster than preg_match().

Wrong:

if (function_exists('finfo_open')) {

Correct

if (class_exists('finfo') && defined('FILEINFO_MIME_TYPE')) {

Simply save results of checks in properties:

if (function_exists('finfo_open')) {
if (ini_get('mime_magic.magicfile') && function_exists('mime_content_type')) {