Dynamic image path with token for drupal

Currently I use FCKEditor and IMCE for online article writing.  But When I upload image in the IMCE browser . I can only upload the image into an existing directory.   A directory need to be created with the IMCE administration interface before your image upload.

If you have only a few images to upload, this will not cause any problems, but because I have quite a few category of content and I ‘d like to put each image under each it’s own directory , I will have to use a few more modules for implementation of dynamic image path placement.

The required modules

Of course Drupal token module is the basic of any dynamic path solution. We will also need the following module:

  • CCK
  • cck filefield
  • cck imagefield
  • filefield path (this is the core module for dynamic image path )

Steps for configuration of dynamic image path

  • First we have to add one image field to the content type we want to use using the CCK field definition interface. Add an imagefield to the content type , the purpose of this imagefield is for storing our content images for the content.

cck_image 1-1_f


  • Then we will configure this imagefield for the following properties:

cck_image 1-2_f

  • Remember that imagefield is also a special kind of filefield, It has all the filefield features, we will enter ‘[vocab]/[term]’ into the file path definition. these drupal token will be replaced at run-time by the real vocabulary and term of the article and will ensure that our uploaded image will be stored under the defined directory automatically.
  • Now we have to configure the imagefield display property. because CCK imagefield will be attached under the article by default, we have to change this display property at the ‘Display fields’ section. We will change them to ‘hidden’ for both the ‘Teaser’ and ‘Full node’ mode. because we don’t want the uploaded image to be display under the bottom of the content and we ‘re finished with the configuration now!

cck_image 1-4_f

Testing our new dynamic image path feature

Just create a new content and you will notice that there ‘s a  cck imagefield appear in the content creation page:

cck_image 1-5_f

Here we could upload all the images for this article.

Then we have to click ‘Save’ before the uploaded images be moved to the right directory.  Drupal token will only be replaced by the dynamic value after saving the content.

Finally just go to the content where these images will be inserted, use IMCE browser to find the uploaded image under the planned directory and insert the image into the right place of the content.

This solution is not perfect,  but it does work for placing our image under a dynamically created directory!

Leave a Reply

Your email address will not be published. Required fields are marked *

The Answer *