public static function mime($path)
    {
        $mime = false;

        if (is_readable($path)) {
            if (function_exists('finfo_open')) {
                $buffer = file_get_contents($path, false, null, -1, 5012);

                $finfo = finfo_open(FILEINFO_MIME_TYPE);
                $mime = finfo_buffer($finfo, $buffer);
                finfo_close($finfo);

                $buffer = null;
            } elseif (function_exists('mime_content_type')) {
                $mime = mime_content_type($path);
            }
        }

        if ($mime !== false && strpos($mime, 'application/') === 0) {
            $size = filesize($path);
            $mime = $size >= 0 && $size < 2 ? 'text/plain' : $mime;
        }

        return $mime;
    }
public static function mime($path)
    {
        $mime = false;

        if (is_readable($path)) {
            if (function_exists('finfo_open')) {
                $buffer = file_get_contents($path, false, null, -1, 5012);

                $finfo = finfo_open(FILEINFO_MIME_TYPE);
                $mime = finfo_buffer($finfo, $buffer);
                finfo_close($finfo);

                $buffer = null;
            } elseif (function_exists('mime_content_type')) {
                $mime = mime_content_type($path);
            }
        }

        if ($mime !== false && strpos($mime, 'application/') === 0) {
            $size = filesize($path);
            $mime = $size >= 0 && $size < 2 ? 'text/plain' : $mime;
        }

        return $mime;
    }
public static function mime ( $ path ) { $ mime = false ; if ( is_readable ( $ path ) ) { if ( function_exists ( 'finfo_open' ) ) { $ buffer = file_get_contents ( $ path , false , null , - 1 , 5012 ) ; $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mime = finfo_buffer ( $ finfo , $ buffer ) ; finfo_close ( $ finfo ) ; $ buffer = null ; } elseif ( function_exists ( 'mime_content_type' ) ) { $ mime = mime_content_type ( $ path ) ; } } if ( $ mime !== false && strpos ( $ mime , 'application/' ) === 0 ) { $ size = filesize ( $ path ) ; $ mime = $ size >= 0 && $ size < 2 ? 'text/plain' : $ mime ; } return $ mime ; }
Get mimetype from file, return `false` if file is invalid

@param string $path
@return string|bool
Get mimetype from file return false if file is invalid