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;
    }
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;
    }
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 ; }
Is the given filename of an allowed file type?

Empty whitelist is interpretted as "any file type is allowed" rather
than "no file can be uploaded".

@param string $filename the file name
@param string|array $whitelist list of allowed file extensions
@return boolean True if the file type is allowed, false if not
Is the given filename of an allowed file type?