2

When a file/image is uploaded via Drupal, they go into a common directory specified by the administrator.

However, is there a way to specify where the files will be uploaded, according to their node ID? For example, say, a person creates a page and Drupal assigns it an ID of 1234; thus, the uploaded files will go into {specified_location}/1234_files/.

2 Answers 2

3

You can use the File (Field) Paths module in combination with the Token module for this.

  1. Enable module
  2. Go to admin/structure/types/manage/your_content_type/fields/your_file_field
  3. Make sure Enable File (Field) Paths? is enabled.
  4. Under File (Field) Path settings you can now use e.g. myfiles/[node:nid]
1

Try the File (Field) Paths module with Token module

Token

Tokens are small bits of text that can be placed into larger documents via simple placeholders, like %site-name or [user]. The Token module provides a central API for modules to use these tokens, and expose their own token values.

File (Field) Paths

The File (Field) Paths module extends the default functionality of Drupal's core Upload module, the FileField module and many other File Upload modules by adding the ability to use node tokens in destination paths and filenames.

On the file field edit page you can use Replacement Patterns for File Directory field

2
  • Op asks for [nid]. I think token does not support [nid] token out of the box.
    – devunder
    Commented Jul 6, 2014 at 5:47
  • @undersound Thanks I updated my answer to make it valid Commented Jul 6, 2014 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.