Php Filemanager将文件保存到自定义表中

Php Filemanager将文件保存到自定义表中,php,moodle,Php,Moodle,我正在使用Moodle 3.1+。我用filepicker上传了一个文件。它工作得很好。但是filepicker只显示上传的文件名。我想在文件选择器中显示上传的图像,这似乎是不可能的。另一种选择是使用filemanager,但它需要额外的参数,如contextid,而在我的例子中没有。我正在将上传的图像路径插入我创建的表中。那么,如何使用filemanager将文件保存到自定义表中呢 file_save_draft_area_files($data->attachments, $conte

我正在使用Moodle 3.1+。我用filepicker上传了一个文件。它工作得很好。但是filepicker只显示上传的文件名。我想在文件选择器中显示上传的图像,这似乎是不可能的。另一种选择是使用filemanager,但它需要额外的参数,如contextid,而在我的例子中没有。我正在将上传的图像路径插入我创建的表中。那么,如何使用filemanager将文件保存到自定义表中呢

file_save_draft_area_files($data->attachments, $context->id, 'mod_glossary', 'attachment',
                   $entry->id, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 50));

首先,在表单中创建filemanager元素:

$filemanageropts = $this->_customdata['filemanageropts'];
$mform->addElement('filemanager', 'attachment',get_string('displayedcontent', 'block_helloworld'), null, $filemanageropts);
注意:附件与我的自定义表中的名称相同。因此,此字段将填充文件itemid

然后,在表单逻辑脚本中将文件保存到自定义区域:

//form has been submitted
file_save_draft_area_files($form_submitted_data->attachment, $context->id, 'block_helloworld', 'attachment',
$form_submitted_data->attachment, array('subdirs' => 0, 'maxbytes' => 500000, 'maxfiles' => 1));
然后,在加载表单数据时:使用以下命令准备在草稿区域中调用的内容:

$draftitemid = $helloworldpage->attachment ; 
        file_prepare_draft_area($draftitemid, $context->id, 'block_helloworld', 'attachment', $helloworldpage->attachment,
            array('subdirs' => 0, 'maxbytes' => 5000000, 'maxfiles' => 1));
资源:


首先,在表单中创建一个filemanager元素:

$filemanageropts = $this->_customdata['filemanageropts'];
$mform->addElement('filemanager', 'attachment',get_string('displayedcontent', 'block_helloworld'), null, $filemanageropts);
注意:附件与我的自定义表中的名称相同。因此,此字段将填充文件itemid

然后,在表单逻辑脚本中将文件保存到自定义区域:

//form has been submitted
file_save_draft_area_files($form_submitted_data->attachment, $context->id, 'block_helloworld', 'attachment',
$form_submitted_data->attachment, array('subdirs' => 0, 'maxbytes' => 500000, 'maxfiles' => 1));
然后,在加载表单数据时:使用以下命令准备在草稿区域中调用的内容:

$draftitemid = $helloworldpage->attachment ; 
        file_prepare_draft_area($draftitemid, $context->id, 'block_helloworld', 'attachment', $helloworldpage->attachment,
            array('subdirs' => 0, 'maxbytes' => 5000000, 'maxfiles' => 1));
资源:


我想保存在自定义表中。在这里,它将保存到mdl_文件表中。在自定义表中,您将得到
附件
字段,其中填充了
mdl_文件
中的对象id,该对象id负责处理文件,因此您应该能够管理您的文件。我在哪个上下文中保存文件?@davosmith给出了我希望保存在自定义表中的一个很好的示例。在这里,它将保存到mdl_文件表中。在自定义表中,您将获得
附件
字段,其中填充了
mdl_文件
中的对象id,该对象id负责处理文件,因此您应该能够管理您的文件。在哪个上下文中保存文件?@davosmith给出了一个很好的建议