Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Experimental project
This is a sandbox project, which contains experimental code for developer use only.
This module was created to preserve filenames of uploaded documents. When a file is uploaded through Drupal, a folder is created with the filename and a subfolder with the file's timestamp. The file is moved into this folder and renamed to the value stored in the filename attribute.
Requirements
Configuration
The module can be configured at /admin/config/media/upload_archives.
There are two options available for configuration:
- Upload Archives directory name: an optional subdirectory of public:// or private:// where files managed by Upload Archives will be stored.
- Timestamp format: Whether subdirectories should be labelled with a formatted datetime string or a raw timestamp.
Function
This module's functionality is largely provided by two hooks:
hook_file_update:
- Creates a directory from the file's filename attribute, replacing periods with underscores.
- Creates a subdirectory with either a formatted datetime string from the file's timestamp attribute (
YYYY
-MM
-DD
_HH
h-MM
m-SS
s) or the raw timestamp. - Moves the file into the datetime subdirectory and renames it with the filename attribute (preferred name).
hook_file_delete:
- Checks if the file being deleted is located in a folder that shares its filename.
- After the file is deleted, the hook removes the associated datetime directory.
- If the filename directory is now empty, it is also deleted.