Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Permanent Media File Delete

Security covered Maintenance fixes only 43 sites

This module permanently deletes orphaned media files when an existing media item is replaced with a new one. It works in conjunction with the Media File Delete module to clean up unused files.

When you replace the file of a media item, Drupal keeps the old file on disk forever. Permanent Media File Delete removes files that media items no longer use, so replaced images, documents, audio and video files do not pile up in your file system and backups.

A file is only removed when nothing else uses it: files shared with other media items or content are always kept.

Features

  • Removes replaced files when the file of a media item is replaced or removed, for every media type whose source is a file or image field, including your own media types and multi-value and translated fields.
  • Choose the media types it applies to.
  • Delete right away, or later: mark unused files as temporary, so cron deletes them after the period set in the file system settings, giving you time to undo a mistake.
  • Revision aware: optionally keep files that older revisions use, so reverting still works; they are removed when those revisions are deleted.
  • Clean up deleted media: optionally remove the files of deleted media items, including those of their older revisions.
  • Unused files report: lists the permanent files that nothing uses, with their size, filtered by age and type (images, video, audio, documents), and deletes the selected or all listed files in a batch. Use it to clean up files left behind before the module was installed.
  • CSV export of the unused files, to review them before deleting.
  • Protected files: URI patterns, such as public://logos/* or *.svg, whose files are never deleted, by the module, the report, Drush or cron. Use them for files linked from templates or code.
  • Automatic cleanup, off by default: delete unused files on cron, only those uploaded at least a number of days ago, and a limited number per run.
  • Status report: the number and size of unused files, and a warning when unused files are marked as temporary but temporary files are never deleted.
  • Drush command to list and delete unused files, by age and type.
  • Logged: every removed file is written to the site log, and editors see a message.

Requirements

  • Drupal 10.3 or later, or Drupal 11.
  • The core Media and File modules.

Installation

Install as you would normally install a contributed Drupal module. For further information, see Installing Drupal Modules.

composer require drupal/permanent_media_file_delete
drush pm:enable permanent_media_file_delete

Configuration

  1. Give site administrators the Administer permanent media file delete permission.
  2. Go to Configuration » Media » Permanent media file delete (/admin/config/media/permanent-media-file-delete) and choose:
    • the media types (none checked means all types with files);
    • whether unused files are deleted right away or marked as temporary;
    • whether to keep files that older revisions use;
    • whether to remove the files of deleted media items;
    • whether editors see a message when a file is removed;
    • the protected files;
    • automatic cleanup on cron.
  3. Review files left over from before, under the Unused files tab.

Good to know

  • Deleted files cannot be restored. Choose Mark them as temporary if you want a safety net, and keep backups.
  • The unused files report relies on Drupal's file usage records. Files linked only from places that do not record usage, such as hard-coded links in templates, also appear there: check before deleting, and protect them.
  • Automatic cleanup deletes any permanent file that nothing uses, not only media files. Review the report, and protect files, before turning it on.

Upgrading

Run drush updatedb. The default settings match the behavior of 1.0, and new features are off until you turn them on. The module no longer requires Media File Delete; you can still use it to choose, when deleting a media item, whether to delete its file.

Support

Report bugs and request features in the issue queue.

Drupal 10–11

Ask your assistant about Permanent Media File Delete

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

  • file Drupal core
  • media Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
6
Tracked since
Apr 2024
Latest release
2 weeks ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
1.0.6 Stable 10–11 Oct 30, 2026
1.0.5 Stable 10–11 Oct 16, 2026
1.0.4 Stable 9–10 Apr 24, 2024
1.0.x-dev Dev 9–10 Apr 24, 2024
1.0.1 Stable 9–10 Apr 23, 2024
1.0.0 Stable 10–11 Apr 23, 2024