I need to create a javascript object in the header of my product pages (Vive le Ubercart) that contains the full URL paths of all my thumbnail images. (in case you're interested, I'm attaching jQuery event handlers to each thumbnail image, so my javascript object maps the 'src' attribute of each thumbnail image to the larger version of itself, then changes the 'src' value on the main (large) image)
Using Drupal 5.x, UC, Imagecache, I was able to override the product image div's using template.php against the UC product_image theme, but this was only because imagecache reproduced the path structure of the files location _after_ the preset name in the path.
But now, after learning that UC was now compatible with D6, and creating a new dev site with new 'stuff', my code is outputting incorrect URLs for my thumbnails. It's because A) D6 puts files in "/sites/default/files/" and ImageCache no longer includes the leading path after the preset name. For example:
$thumbnail_src = file_create_url(file_directory_path() .'/imagecache/uc_thumbnail/'. $thumbnail['filepath']);
gave me :
http://mysite.com/files/imagecache/uc_thumbnail/files/myimage.png
but now it gives me:
http://mysite.com/sites/default/files/imagecache/uc_thumbnail/sites/defa...
but that's not where the image is. The image URL is this:
http://mysite.com/sites/default/files/imagecache/uc_thumbnail/myimage.png
As far as I know, the only key in the thumbnail (image) object available to me is 'filepath' which gives the "/sites/default/files/myimage.png" but I need to insert the "/imagecache/uc_thumbnail/" there.
Is there a way to call this path without writing out on img tag?
Or, am I just as well off to write a string substitution routine to insert the preset name into the path? It just feels kludgy to do that, so I wanted to find out if there is a way to get JUST the file path back, after it has been converted to an imagecache path.
Does that make sense?
Thanks!
Comments
Comment #1
ccshannon commentedHaha - I figured it out. The $thumbnail is a data row object from the files table. There is a field called 'filename' that is exactly what I want.
So the answer is, if you want to reconstruct the imagecache path of your image, use $image['filename'] to get the filename without the path.