在moodle File API 中永久保存后删除草稿文件

RYN*_*RYN 2 php moodle file-upload file-manager

我正在使用moodlefilemanager从用户那里获取文件并像这样永久保存它:

$fs = get_file_storage();
$pluginname='profile_field_fileupload';
$pluginfolder= 'profile_field_profileimage';


$draftitemid=file_get_submitted_draft_itemid($this->inputname);
if (empty($entry->id)) {
    $entry = new stdClass;
    $entry->id = $this->userid;
}
$context = context_user::instance($this->userid);
$files = $fs->get_area_files($context->id, $pluginname,$pluginfolder,false,'',false);
    foreach ($files as $file) {
        $file->delete();
}

file_save_draft_area_files($draftitemid, $context->id, $pluginname,$pluginfolder,$entry->id,array('subdirs'=>false, 'maxfiles'=>1));
Run Code Online (Sandbox Code Playgroud)

但是草稿仍然存在。
保存后如何删除草稿?

dav*_*ith 7

等待几天 - Moodle 的 cron 进程在那之后会自动清理草稿文件(延迟是为了确保您还没有打开和使用表单的副本)。

请记住,草稿区文件不会占用您服务器上的额外存储空间,因为所有具有相同内容的文件只存储一次,“mdl_files”表中的多个条目都指向服务器硬盘上的相同物理位置。