protected function isMimetypeAllowed($filename, $default = "")
    {
        $numAllowed = sizeof($this->allowedMimeTypes);
        $numDenied = sizeof($this->deniedMimeTypes);

        if ($numAllowed == 0 && $numDenied == 0) {
            return true;
        }

        /**
         * Try to retrieve the mime type of the file
         */
        // first, try as an image. May cause exception if not an image, so do not trigger errors
        if (@($data = getimagesize($filename))) {
            $mimetype = $data['mime'];
        } else {
            if (function_exists('finfo_open') && function_exists('finfo_file')) {
                $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
                $mimetype = finfo_file($finfo, $filename);
                finfo_close($finfo);
            } else {
                // this is deprecated
                $mimetype = function_exists('mime_content_type') ? mime_content_type($filename) : $default;
            }
        }

        // validate the mime type agains the white and blacklists
        if ($numAllowed > 0 && !in_array($mimetype, $this->allowedMimeTypes)) {
            return false;
        }
        if ($numDenied > 0 && in_array($mimetype, $this->deniedMimeTypes)) {
            return false;
        }

        return true;
    }