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.


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?


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


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.

  • Just a warning - that module is really buggy – Clive Mar 10 '14 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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