Filemanager - saving to specified directory

Re: Filemanager - saving to specified directory

аз Davo Smith -
Number of replies: 3
Сурати  корбар Core developers Сурати  корбар Particularly helpful Moodlers Сурати  корбар Peer reviewers Сурати  корбар Plugin developers

Well, if you really need the files saved in a directory, rather than inside the files API (you haven't explained why this is a requirement, but I'll assume for the moment that you have a good reason for doing so), then the following code should work.

$fs = get_file_storage();
$files = $fs->get_area_files($contextid, $component, $filearea, $itemid, 'filename', false);
foreach ($files as $file) {
$file->copy_content_to($destdir.'/'.$file->get_filename()); }

This code assumes you've already used the standard Moodle functions to save the files from the draft area into a known location (although, in theory, you could use the $contextid, $component, $filearea and $itemid of the draft area to do this). If you want to, you could add a $file->delete() call inside the loop to delete the files from the Moodle API at the same time.

I've also assumed you don't want the subdirectories (only the files themselves), so I've passed 'false' as the last param to get_area_files.


In reply to Davo Smith

Re: Filemanager - saving to specified directory

аз Lloyd D -

I've been trying to do the same thing... I want to save from the file manager to my own specified directory but I don't want it to be initially saved in the default Moodledata folder.. also I tried changing to use a filepicker in my form but when I try and save the file in the save_settings function it does not have access to the MoodleQuickForm class as it's not parsed/available in the function. I'd really appreciate any help on this problem

In reply to Davo Smith

Re: Filemanager - saving to specified directory

аз Lloyd D -

Hi Davo, how can I load the files that are copied to the specified destination into the file manager? At the moment the files are:

  1. saved to the default Moodledata folder
  2. then copied to the specified directory
  3. then the files are loaded from the Moodledata folder into the file manager.

How can I load the files from the directory in which the files were copied to?