我创建了一个新表单,其中包含一个新的“文件管理器”元素,它可以工作,并将上传的文件存储到数据库中的 mdl 文件表中,但它没有将文件保存到服务器,所以我无法在网站上显示它们,任何人都可以帮忙!
else if ($fromform = $mform->get_data()) {
// $DB->insert_record('gallery',$recordinsert);
$messagetext = file_save_draft_area_files($fromform->teacherPhotos, $context->id, 'mod_glossary', 'attachment',
$draftitemid, array('subdirs' => 0, 'maxbytes' => 200000, 'maxfiles' => 50),$messagetext);
$messagetext = file_rewrite_pluginfile_urls($messagetext, 'pluginfile.php',
$context->id, 'mod_glossary', 'attachment', $draftitemid);
$out = array();
/** @var stored_file[] $files */
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_glossary', 'attachment',$draftitemid);
foreach ($files as $file) {
$filename = $file->get_filename();
$url = moodle_url::make_pluginfile_url
($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename(), false);
$out[] = html_writer::link($url, $filename);
}
$br = html_writer::empty_tag('br');
echo implode($br, $out);
// echo '<br><img src="'.$url.'">';
}