public function is_allowed_file_type($filename, $whitelist) {

        $allowedextensions = $this->expand($whitelist);

        if (empty($allowedextensions) || $allowedextensions == ['*']) {
            return true;
        }

        $haystack = strrev(trim(core_text::strtolower($filename)));

        foreach ($allowedextensions as $extension) {
            if (strpos($haystack, strrev($extension)) === 0) {
                // The file name ends with the extension.
                return true;
            }
        }

        return false;
    }