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:

  1. Creates a directory from the file's filename attribute, replacing periods with underscores.
  2. Creates a subdirectory with either a formatted datetime string from the file's timestamp attribute (YYYY-MM-DD_HHh-MMm-SSs) or the raw timestamp.
  3. Moves the file into the datetime subdirectory and renames it with the filename attribute (preferred name).

hook_file_delete:

  1. Checks if the file being deleted is located in a folder that shares its filename.
  2. After the file is deleted, the hook removes the associated datetime directory.
  3. If the filename directory is now empty, it is also deleted.

Project information

  • Module categories: Media
  • Created by ginosuave on , updated