protected function getMIMEType($file)
    {
        $mime = 'application/octet-stream';

        if (function_exists('finfo_open') && $info = @finfo_open(FILEINFO_MIME)) {
            if (($mime = @finfo_file($info, $file)) !== \false) {
                $mime = explode(';', $mime);
                $mime = trim($mime[0]);
            }
        }

        return $mime;
    }