public function validateSubmitValue($value) {

        if (empty($value)) {
            return;
        }

        $filetypesutil = new \core_form\filetypes_util();
        $whitelist = $filetypesutil->normalize_file_types($this->_options['accepted_types']);

        if (empty($whitelist) || $whitelist === ['*']) {
            // Any file type is allowed, nothing to check here.
            return;
        }

        $draftfiles = file_get_all_files_in_draftarea($value);
        $wrongfiles = array();

        if (empty($draftfiles)) {
            // No file uploaded, nothing to check here.
            return;
        }

        foreach ($draftfiles as $file) {
            if (!$filetypesutil->is_allowed_file_type($file->filename, $whitelist)) {
                $wrongfiles[] = $file->filename;
            }
        }

        if ($wrongfiles) {
            $a = array(
                'whitelist' => implode(', ', $whitelist),
                'wrongfiles' => implode(', ', $wrongfiles),
            );
            return get_string('err_wrongfileextension', 'core_form', $a);
        }

        return;
    }
public function validateSubmitValue($value) {

        if (empty($value)) {
            return;
        }

        $filetypesutil = new \core_form\filetypes_util();
        $whitelist = $filetypesutil->normalize_file_types($this->_options['accepted_types']);

        if (empty($whitelist) || $whitelist === ['*']) {
            // Any file type is allowed, nothing to check here.
            return;
        }

        $draftfiles = file_get_all_files_in_draftarea($value);
        $wrongfiles = array();

        if (empty($draftfiles)) {
            // No file uploaded, nothing to check here.
            return;
        }

        foreach ($draftfiles as $file) {
            if (!$filetypesutil->is_allowed_file_type($file->filename, $whitelist)) {
                $wrongfiles[] = $file->filename;
            }
        }

        if ($wrongfiles) {
            $a = array(
                'whitelist' => implode(', ', $whitelist),
                'wrongfiles' => implode(', ', $wrongfiles),
            );
            return get_string('err_wrongfileextension', 'core_form', $a);
        }

        return;
    }
public function validateSubmitValue ( $ value ) { if ( empty ( $ value ) ) { return ; } $ filetypesutil = new \ core_form \ filetypes_util ( ) ; $ whitelist = $ filetypesutil -> normalize_file_types ( $ this -> _options [ 'accepted_types' ] ) ; if ( empty ( $ whitelist ) || $ whitelist === [ '*' ] ) { // Any file type is allowed, nothing to check here. return ; } $ draftfiles = file_get_all_files_in_draftarea ( $ value ) ; $ wrongfiles = array ( ) ; if ( empty ( $ draftfiles ) ) { // No file uploaded, nothing to check here. return ; } foreach ( $ draftfiles as $ file ) { if ( ! $ filetypesutil -> is_allowed_file_type ( $ file -> filename , $ whitelist ) ) { $ wrongfiles [ ] = $ file -> filename ; } } if ( $ wrongfiles ) { $ a = array ( 'whitelist' => implode ( ', ' , $ whitelist ) , 'wrongfiles' => implode ( ', ' , $ wrongfiles ) , ) ; return get_string ( 'err_wrongfileextension' , 'core_form' , $ a ) ; } return ; }
Check that all files have the allowed type.

@param int $value Draft item id with the uploaded files.
@return string|null Validation error message or null.
Check that all files have the allowed type .