I've created a Moodle module that uploads a file... or is supposed to.
I've tried to follow the documentation at https://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms#Load_existing_files_into_draft_area
I get the error messages:
Warning: Invalid argument supplied for foreach() in /home/learndom/public_html/moodle/lib/pear/HTML/QuickForm.php on line 1279
Warning: Invalid argument supplied for foreach() in /home/learndom/public_html/moodle/lib/pear/HTML/QuickForm.php on line 1279
I'm assuming this error comes from my mod_form.php file but that makes no sense as I've followed the documentation that exists and it contains:
$maxbytes = 10485760;
$mform->addElement('filemanager',
'userfile',
get_string('file', 'presentationupload'),
null,
array('subdirs' => 0,
'maxbytes' => $maxbytes ,
'areamaxbytes' => 10485760,
'maxfiles' => 1,
'accepted_types' => array('zip'),
'return_types'=> FILE_INTERNAL));
Second Problem:
I seem to have correctly uploaded the file to the draft area as mdl_files contains a record with the filename in it.
However I am at a loss as to how to make the section which says to save the files https://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms#Store_updated_set_of_files:
Store updated set of files
if ($data = $mform->get_data()) { // ... store or update $entry file_save_draft_area_files($data->attachments, $context->id, 'mod_glossary', 'attachment', $entry->id, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 50)); }
If someone could provide a clue here I would be grateful.
Cheers
Dave