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