Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Filename max length

No security coverage Under active development

Filename max length adds a maximum filename length to the filename sanitization options of Drupal core, and provides a Drush command to apply these options to files already on your site.

Long filenames are a common source of trouble: paths that exceed file system or archive limits, broken downloads, unreadable URLs. Core can transliterate filenames, replace whitespace and lowercase them, but it cannot limit their length. This module fills that gap.

Features

  • A Maximum filename length setting, next to core's sanitization options on Configuration > Media > File system.
  • Uploaded filenames longer than the limit are shortened before their extension, and trailing dots, dashes, underscores and spaces are trimmed.
  • The limit applies after the File module options (transliteration, lowercase, etc.) and before core's security rules, so dangerous extensions are still handled.
  • A Drush command, filename-max-length:rename, renames existing files according to all the current sanitization options, as if they were uploaded today.

Requirements

  • Drupal 11.3 or later, or Drupal 12.
  • The core File module.
  • Drush 13.7 or later, only for the rename command.

Configuration

Go to Configuration > Media > File system (/admin/config/media/file-system) and set the Maximum filename length in the Sanitize filenames section. The length counts characters, extension included. 0 means no limit, and the maximum is 240, the limit of core's FileNameLength constraint.

Core's security rules may still add a few characters (.txt, _). When a file with the same name already exists, core adds a numeric suffix (_0, _1…), which can also exceed the limit.

Renaming existing files

# List the files that would be renamed.
drush filename-max-length:rename --dry-run

# Rename them. Back up the files and the database first.
drush filename-max-length:rename --yes

The command renames every permanent managed file whose name is not compliant. These keep working after the rename:

  • file and image fields, on nodes as on media, which reference files by ID;
  • images inserted in formatted text through CKEditor 5, whose src is rewritten by the editor_file_reference filter;
  • image styles: the derivatives of the old name are flushed.

These are not updated:

  • hard-coded links to the old file URLs, in formatted text or outside the site;
  • unmanaged files.

Ask your assistant about Filename max length

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

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Nov 2026
Latest release
3 hours ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

Version Type Core PHP Release date
1.0.0-alpha1 Pre-release 11 Nov 12, 2026