LMSouq
moodle-core Open

removing draft file after saving permanently in moodle File API

AR
Ariyan
1 month ago
3 views
Problem Description
I'm using moodle `filemanager` to get a file from user and save it permanently like this: $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)); But draft still exists. How should I remove draft after saving it?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base