## General developer forum

### File Manager

File Manager

I am successfully able to upload files using filemanager. I am also able to display them after the resource is saved. But when the user edits the resource, the files are not visible in the file uploader section. What could be the probable cause for this?

Average of ratings: -
Re: File Manager

You probably missed the step where you repopulate the 'draft' area of the control with the files that were saved into the 'real' file area when the form was submitted.

Before you show the form, you should call:

file_prepare_standard_filemanager()

to copy files into the draft area (just like, after the form is submitted, you need to call file_postupdate_standard_filemanager() to copy the files from the draft area into their final location).

Average of ratings: -
Re: File Manager

I have saved the file from draft to real in lib.php and the form is being displayed in mod_form.php.
The first argument to file_prepare_standard_filemanager is data. Does this refer to the return value of file_postupdate_standard_filemanager?

Average of ratings: -
Re: File Manager

The first argument is the data object you are going to pass to the form to initialise the form data.

So, if the filemanager is the only data you are going to add to the form, you can do something like this:

$data = new stdClass(); // Alternatively, initialise the form data in whatever way you are currently doing.$data = file_prepare_standard_filemanager($data, ...);$form->set_data($data); Average of ratings: - Re: File Manager I tried doing that but got this error: Call to undefined method MoodleQuickForm::set_data() Average of ratings: - Re: File Manager No, you don't call set_data() on your MoodleQuickForm object, you call it on your moodle_form object, just like you normally do for every form you use. So, it should look like:$form = new my_custom_form();
$dataforform = [whatever you need to do to get the current data for the form];$dataforform = file_prepare_standard_filemanger($dataforform, ...);$form->set_data($dataforform); if ($form->is_cancelled()) {
...
} else if ($submitdata =$form->get_data()) {
...
file_postupdate_standard_filemanager(...);
...
} else {
\$form->display();
}

Average of ratings: -
Re: File Manager

Thanks Davo. The explanation for the arguments were not clear in the docs. It's working now.

Average of ratings: -