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.

I have a cck image field and I have the "uploads" directory in the files folder.

I want the images of these nodes are saved to the directory with the name of the node id and then the image file. Suppose if the node id is 4 then the image should be saved to the following directory.

files/uploads/4/filename

the directory with the name of "4" should be created programmatically.

Which hook should I use for this and how to achieve this? Any one who have some idea?

share|improve this question

3 Answers 3

up vote 0 down vote accepted

You have to use following module https://drupal.org/project/filefield_paths . then you can add tokens for it . enter image description here

share|improve this answer

You should use File (Field) Paths which supports Drupal 7..

Project page says

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.

In simple terms, File (Field) Paths allows you to automatically sort and rename your uploaded files using token based replacement patterns to maintain a nice clean filesystem.

share|improve this answer
    
Just a warning - that module is really buggy –  Clive Mar 10 at 13:49

You can use the Upload path module:

After operating for some time, a website may build up thousands of files in inside the files folder. This uploadpath module allows you to keep the files in the files folder neatly organized in subfolders. It can also allow you to automatically rename uploaded files based on file description or node title.

The module uses the Token module for specifying path patterns. It is relatively a small module and you can take a look at its code to get a hint of how it achieves this.

share|improve this answer

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.