public static function analyzeFile($path, $magic_db = null,
                                       $opts = array())
    {
        if (Horde_Util::extensionExists('fileinfo')) {
            $res = empty($magic_db)
                ? finfo_open(FILEINFO_MIME)
                : finfo_open(FILEINFO_MIME, $magic_db);

            if ($res) {
                $type = trim(finfo_file($res, $path));
                finfo_close($res);

                /* Remove any additional information. */
                if (empty($opts['nostrip'])) {
                    foreach (array(';', ',', '\\0') as $separator) {
                        if (($pos = strpos($type, $separator)) !== false) {
                            $type = rtrim(substr($type, 0, $pos));
                        }
                    }

                    if (preg_match('|^[a-z0-9]+/[.-a-z0-9]+$|i', $type)) {
                        return $type;
                    }
                } else {
                    return $type;
                }
            }
        }

        return false;
    }