[2.5]Load files to file manager element!!!

[2.5]Load files to file manager element!!!

by Le Quoc -
Number of replies: 0

Hi

I'm new in moodle. I'm trying to develop a new module. I add a file manager element to the form and i can use it to upload and browse files.

$mform->addElement('filemanager', 'attachments', get_string('attachment', 'mod_mymodule'), null,
array('subdirs' => 0,'maxfiles' => 50,
'accepted_types' => array('audio') ));

I can browse files and save files follow this code:

if ($data = $mform->get_data()) {
file_save_draft_area_files($data->attachments, $context->id, 'mod_mymodule', 'attachment',
$mymodule->id, array('subdirs' => 0,'maxfiles' => 50));
}

But i dont know how to load those files to file manager element when i edit the module.I'm using this code but it doesn't work.

function data_preprocessing(&$default_values) {
if ($this->current->instance) {
$draftitemid = file_get_submitted_draft_itemid('attachments');
file_prepare_draft_area($draftitemid, $this->context->id, 'mod_mymodule', 'attachment', 0, array('subdirs'=>true));
$default_values['attachments'] = $draftitemid;
}
}

Can someone show me the right way to do?

Many thanks!

Jason

Average of ratings: -