Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

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

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

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

Your Answer

 
discard

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.