When removing an image from a node I notice that the file is actually left on the server, are there any plans to have files removed from the directory when they are removed from a node? I'm seeing difficulties in managing many images(hundreds or thousands) without such an option.

Thanks for reading.

Comments

philsward’s picture

Title: File removal » +1 File removal

I too noticed the same thing tonight, playing with alpha3. I am working on a classifieds website where I will be at the mercy of many users uploading images and really don't want the overhead of cleaning up images...

Otherwise, keep up the great work!

philsward’s picture

Title: +1 File removal » File removal

I made a boo-boo in the 'Issue title' on my last post... I meant to add a +1 for the issue and added it to the title.
I am using this post to fix my mistake. (oops!!)

NecroHill’s picture

subscribing

ephyr’s picture

Subscribing

wmnnd’s picture

I would propose to not remove them but moving them to a special folder e. g. called "deleted".
So, if you have deleted an image by error, you will be able to recover it, but you can also easily delete images which are no longer needed.

highvoltage’s picture

A trashbin type folder is a great idea actually.

basicmagic.net’s picture

subscribe

frankcarey’s picture

subscribe

philsward’s picture

Issue tags: +delete, +remove

I think an option for a trashbin is a great idea but I think the best overall solution is to have two options:

1) Delete for good
2) Delete to trashbin with a token configurable path to where the trashbin would be located.

On a site where there are many users, they wouldn't have access to the trashbin to recover images unless it is specified within the module to grant them that access. Then you have the problem of making a trashbin for every user and giving them the ability to either permanently delete a picture or keep it in "their" trashbin. Totally possible but that is a lot of work... The killfile module might provide useful in this situation...

I know that the proposed trashbin is probably a singular trashbin that only admin users would have access to but ya... just throwing out some ideas and associated problems.

I personally want to see a 'remove file from server when image is removed' type of option in the field configuration. On the sites I run with a lot of users, I don't want to give them their own trash bin. What an administration nightmare! lol

The whole purpose of deleting the pictures from the server is to reduce the file size footprint from the server keeping it clean and tidy and I don't think that the average user should be the final decision maker on whether or not the server is kept clean.

Just my two cents. I hope this feature is in the sights to get implemented soon!!

spjsche’s picture

subscribing

account-deletion-needed’s picture

Subscribing

account-deletion-needed’s picture

Here's some code I quickly threw together which deletes any unused image files when cron is executed:

/**
* hook_cron: delete unused image files
*/
function my_module_cron() {
  if (module_exists('content')) {
    $tables = array();
    $cols = array();
    $fields = content_fields();
    $i = 0;
    foreach ($fields as $field) {
      if ($field['type'] == 'image') {
        $db_info = content_database_info($field);
        foreach ($db_info['columns'] as $col=>$data) {
          if ($col == 'fid') {
            $tables[] = '{' . $db_info['table'] . '} i' . $i;
            $cols[] = "i$i.$data[column] = f.fid";
            $i++;
          }
        }
      }
    }
    
    if ($tables) {
      $tables = implode(', ', $tables);
      $cols = implode(' OR ', $cols);
      $result = db_query("SELECT f.fid, f.filepath FROM {files} f WHERE NOT EXISTS (SELECT 1 FROM $tables WHERE $cols)");
      while ($file = db_fetch_object($result)) {
        file_delete($file->filepath);
        file_delete($file->filepath . '.thumb.jpg');
        db_query("DELETE FROM {files} WHERE fid = $file->fid");
      }
    }
  }
}

To make this work you have to implement it in your own module using hook_cron or you could patch it into imagefield. Alternatively you could also execute it through hook_nodeapi so the files get deleted as you insert/update/delete nodes (though you'd probably have to adjust your module weight for it to work simultaneously).

drewish’s picture

this is a filefield issue, it needs to happen in there.

highvoltage’s picture

So should the issue be moved, a new one made over at file field, or is this already planned and a new issue is unnecessary?

drewish’s picture

highvoltage, i've closed several of these issues as duplicates at this point but people keep opening new ones so i'm not going to bother. go look in the file field queue.

philsward’s picture

Status: Fixed » Active

version 6.x-3.0-alpha7 of FileField will now remove a file from the server when it is removed from imagefield.

I have just tested this feature with alpha 7 and while it WILL remove a file when "removed" then "saved", it will not remove an original file if one is uploaded, removed then another one is uploaded and saved.

Basically, at this time an image will have to be removed then the node saved, then go back into the node and add the new picture. Otherwise the original stays on the server. I will be posting this as an issue on the FileField queue if it hasn't already been caught.

As posted in previous comments, I have no use for a "trash bin", so I won't be posting anything in the FileField queue about implementing some sort of trash / recycle bin. If someone else really has a need for this feature, I am guessing that a new feature request should be filed with the FileField queue.

Update: 2009-02-10
I had created an issue on the FileField issue queue: http://drupal.org/node/369450 regarding the module not removing files from the server if an image is added, then removed and another one is added before a "save" is initiated. The issue was promptly closed with the answer of "The files should clean themselves up on a cron run". After testing this, the files are NOT cleaning themselves up. If you are noticing similar issues, please post on the FileField issue posted above.

drewish’s picture

Status: Active » Fixed

Status: Active » Closed (fixed)
Issue tags: -delete, -remove

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