Reputation: 131
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
Upvotes: 3
Views: 2710
Reputation: 491
It sounds like you are looking to write a custom block, in which case you should be giving block_myblock as the component name instead of mod_assignment.
Each Moodle component which serves files needs to have its own function defined within lib.php to handle file requests. In your case that function wants to be called something like block_myblock_pluginfile()
.
A good example of this is block_html_pluginfile()
which can be found in moodle/blocks/html/lib.php and does something very similar to what you are wanting.
Upvotes: 2