Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/.

share|improve this question
up vote 4 down vote accepted

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]
share|improve this answer

Try the File (Field) Paths module with Token module


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

share|improve this answer
Op asks for [nid]. I think token does not support [nid] token out of the box. – undersound Jul 6 '14 at 5:47
@undersound Thanks I updated my answer to make it valid – Krishna Mohan Jul 6 '14 at 9:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.