The subject says it all.

  1. Create a webform with a file upload component
  2. Submit the form specifying a file to be uploaded
  3. Go to the submission to confirm the file is there
  4. Delete the submission
  5. Watch the file being kept on the webform files directory


Status:Active» Postponed (maintainer needs more info)

I can't confirm this problem on either Drupal 6 or Drupal 7. Both properly delete a file when the submission is deleted. Do you have any other webform-related modules installed?

This is the code that does the deletion, looks like it's working properly:

* Implements _webform_delete_component().
function _webform_delete_file($component, $value) {
  // Delete an individual submission file.
  if (!empty($value[0]) && ($file = webform_get_file($value[0]))) {
    db_query("DELETE FROM {files} WHERE fid = '%d'", $file->fid);

Status:Postponed (maintainer needs more info)» Closed (cannot reproduce)

I've got the same problem in 7.x-3.15.

The delete file function below definitely being called when the submission is deleted:

function _webform_delete_file($component, $value) {
  // Delete an individual submission file.
  if (!empty($value[0]) && ($file = webform_get_file($value[0]))) {

However, file_delete() uses file_usage_list() to check if the file is in use, if it is then an array is returned and the file is not deleted.

In my test case file_delete() is returning

[webform] => Array
            [submission] => Array
                    [8] => 1

and the file is not deleted.

If my observation is correct I think there two solutions - bludgeon file_delete() into deleting the file by using the $force parameter or get webform to release the file before calling file delete.

btw, I'm very much liking the Ajax file upload in the latest dev version.

Version:6.x-3.14» 7.x-4.0-alpha2
Status:Closed (cannot reproduce)» Active

It's the same problem with 7.x-4.0-alpha2.
Uploaded files doesnt gets deleted when deleting the submission. I have tested both with public and private files.
(The files arent used anywhere else then in just that submission).

Thanks guys, I think you're correct. Ever since we switched to using the managed_file element we haven't been removing records from the file_usage table, and therefor files aren't getting deleted. :(

Fortunately we can clean up our records with an update hook and clean up all the ones that have been lingering.

Version:7.x-4.0-alpha2» 7.x-4.x-dev
Component:User interface» Code
Status:Active» Needs review
new448 bytes

The attached patch adds a call to file_usage_delete() so that uploaded files get deleted when their submission is deleted or results are cleared. This does not clean-up files left over from submissions already deleted.

new1.06 KB

The attached patch creates an update hook to clean up files left over from submissions that have been deleted. This patch must be applied along with the patch in #6.

Status:Needs review» Fixed
new1.26 KB

Thanks Liam! This patch needs to be applied to 3.x also, so I applied this backport also. Committed.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.