LMSouq
moodle-core Open

Moodle, upload and store files using moodle forms

FL
flp05
1 month ago
3 views
Problem Description
I'm having some dificulties implementing a moodle upload mechanism using moodle forms. My goal is to let the user/administrator upload images, store them and access later in a block. Currently, I have this in the form: $mform->addElement('filemanager', 'attachments', 'Pic:', null, array('subdirs' => 0, 'maxfiles' => 1,'accepted_types' => '*' )); and this to save the file: if ($draftitemid = file_get_submitted_draft_itemid('attachments')) { file_save_draft_area_files($draftitemid, $context->id, 'mod_assignment', 'attachments', 0, array('subdirs' => false, 'maxfiles' => 1)); } and I try to access the file like this: file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/mod_assignment/attachments') I don't receive any errors but I can't access the file either. I'm using moodle 2.0. Thanks in advance, Take care

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