6

I would like to know what happens if a user uploads an image by image field but doesn't save that node?

It seems that image will be in the directory but no node refers to it. Is there anyway to remove such files?

1 Answer 1

15

The image files will be removed during cron runs.

This happens because the status column in file_managed for those files will still be zero, indicating that they're temporary, and can be safely removed after a period of time.

The responsible code is in system_cron(), in case you need to reproduce/analyse further.

4
  • I just added a content, upload the image but didn't save the node. After running the cron manually that image file was not deleted!, Its status in DB is 1. I use https://www.drupal.org/project/bulk_file_nodes module
    – M a m a D
    Sep 23, 2015 at 9:47
  • @Drupalist I just confirmed on a stock Drupal install that without saving the node, the file's status remains at 0...I think you'll want to talk to the maintainer of the module you're using if it's doing something different, I'm afraid I'm not familiar with it so can't comment
    – Clive
    Sep 23, 2015 at 9:58
  • The bulk_file_nodes will assign 1 to files of unsaved nodes but the Drupal default image field assign 0 to it.
    – M a m a D
    Sep 23, 2015 at 10:10
  • 1
    Certainly sounds like it @Drupalist. Maybe it does it in an attempt to avoid files uploaded first being deleted while the rest are being uploaded (before the node is saved). It's a complete guess. If that's true, though, that seems like a bug as it would be a hell of a bulk file upload that would exhaust DRUPAL_MAXIMUM_TEMP_FILE_AGE
    – Clive
    Sep 23, 2015 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.