0

I am using Drupal 7. When I test my page speed in Google PageSpeed Tools, it says to compress the images. After that I compress the image and uploaded it. The uploaded image placed in files folder like (test_0.png) and the old name is test.png. I have lot of images like that. How to remove images which are not in use.

0

2 Answers 2

0

Try audit Files module

Audit files is designed to perform audits of your upload directory and the corresponding database records. It will cross check that all files in the database have a corresponding physical file, or it will check that all files in the upload directory have a corresponding entry in the database.

This module can be helpful in identifying orphan files that have not been deleted when their corresponding node was removed.

The module has configurable options to ignore specified files and/or directories.

The reports allow you to permanently remove files or database entries that represent orphans.

0

All files uploaded via Drupal UI is managed in file_managed database table and the file usage is maintained in a separate table as file_usage.

There are couple of modules you can give a try for.

  1. Audit Files
  2. Fancy File Delete

Also you can write a query and delete all such which are no more in use. You can setup a cron job which periodically does that for you.

Sample Code: source

//db_query to find all files not attached to a node:
$result = db_query("SELECT fid FROM file_managed WHERE NOT EXISTS (SELECT * FROM file_usage WHERE file_managed.fid = file_usage.fid) ");

//Delete file & database entry
for ($i = 1; $i <= $result->rowCount(); $i++) {
  $record = $result->fetchObject();
  $file = file_load($record->fid);
  if ($file != NULL) {
    file_delete($file);
  } }

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