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

Posted

技术标签:

【中文标题】在moodle File API中永久保存后删除草稿文件【英文标题】:removing draft file after saving permanently in moodle File API 【发布时间】:2014-06-10 19:15:32 【问题描述】:

我正在使用moodle filemanager从用户那里获取文件并将其永久保存,如下所示:

$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));

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

【问题讨论】:

【参考方案1】:

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

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

【讨论】:

以上是关于在moodle File API中永久保存后删除草稿文件的主要内容,如果未能解决你的问题,请参考以下文章

如何在 python 中永久保存列表?

File类

简要记录下localStorage在项目中的应用之一

Gmail /Google 应用程序每小时/每天自动使用脚本/api 永久删除垃圾邮件

Java 关于File使用

在Wordpress上发布保存后更改重定向URL