Question

I'm using the ImageField module together with Imagecache to display a picture for one of my content types.

To display the content body I'm using Contemplate, I'm accessing the path to the image in the following way:

'[...]/imagecache/[preset]/[...]/'.$node->field_picture[0]['filename'] 

This usually works, but it breaks when someone uploads a picture with the same filename as the existing one. The file itself is then automatically named filename_0.jpg instead of filename.jpg, but the filename variable of the ImageField I'm accessing stays filename.jpg.

This of course leads to the old image being displayed. It seems the filename variable does not do what I expected, what would be the correct way to access the Imagecache generated files?

Was it helpful?

Solution

Using the Contemplate module is not recommended since it puts PHP code into the database which is generally considered a security vulnerability and non-performant.

You want to use theme('imagecache', ...) instead, which will return the HTML img tag with the proper path.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top