1
votes

In a Moodle form I perform a file upload using the filemanager element:

$mform->addElement('filemanager', 'attachment',get_string('displayedcontent', 'block_helloworld'), null, $filemanageropts);

Once the form is validated, when I record my instance in the database, I also save the uploaded file using the following function:

file_save_draft_area_files($form_submitted_data->attachment, $context->id, 'block_helloworld', 'attachment',
    $form_submitted_data->attachment, array('subdirs' => 0, 'maxbytes' => 500000, 'maxfiles' => 1));

This is working fine but when I take a look at the DB table mdl_files, I saw that for my file there are 4 rows:

component       fileare     itemid  filepath    filename
block_helloworld    attachment  706783489   /   .
block_helloworld    attachment  706783489   /   test5.pdf
user    draft   706783489   /   .
user    draft   706783489   /   test5.pdf

There are 2 rows for my uploaded file in my component block_helloworld and in the component user. One row has a filename but not the other one!

This sounds strange. Is that normal? When I perform file deletion, how to delete all these files?

Note: I am using moodle v3.0.6

2
Which Moodle version are you using? - Aldo Paradiso

2 Answers

1
votes

The 4 entries are:

  • The folder that your file is in
  • The file itself
  • The folder that the draft version of the file is stored in whilst the form is being edited
  • The draft file whilst the form is being edited

The draft files will be automatically cleaned up after a day or so.

0
votes

As far as I remember, this is normal behaviour. I had this issue, too, but when you cross check (like doing a file upload into a course) you will notice that there are 2 rows, too. Not sure, why but for me it was normal behaviour