/** * if $types is not empty and doesn't include '*' then reject files with extensions not listed in $types * process_upload override */ public function process_upload($saveas_filename, $maxbytes, $types = '*', $savepath = '/', $itemid = 0, $license = null, $author = '', $overwriteexisting = false, $areamaxbytes = FILE_AREA_MAX_BYTES_UNLIMITED) { //types check if ( !empty($types) and ((is_array($types) and !in_array('*', $types)) or $types != '*') ) { $elname = 'repo_upload_file'; //valid check if (isset($_FILES[$elname]) and !empty($_FILES[$elname]['name'])) { $fileext = strtolower(pathinfo($_FILES[$elname]['name'], PATHINFO_EXTENSION)); $allowedext = is_array($types) ? $types : array($types); foreach ($allowedext as $k => $v) { $allowedext[$k] = strtolower(pathinfo($v, PATHINFO_EXTENSION)); } //check extensions if (!in_array($fileext, $allowedext)) { throw new moodle_exception('invalidfiletype', 'repository', '', get_mimetype_description(array('filename' => $_FILES[$elname]['name']))); } } } //call original return $this->process_upload_original($saveas_filename, $maxbytes, $types, $savepath, $itemid, $license, $author, $overwriteexisting, $areamaxbytes); }