Drupal and DB access

Posts: 70
Joined: 04/14/2008

I'm writing a bit of custom php to integrate a product feature into a storefront -- specifically, I'd like to access the file paths for product images from within a php function. While it would be easy enough to write a custom MySQL query to pull the pathnames from the files table, I'm wondering if there isn't a more 'Drupal' manner of doing this? Apologies if I'm missing something obvious -- I'm new to Drupal.

Posts: 1290
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

Not exactly "easy" as saying uc_product_image(); or something, but here's how bemson did it for my uc_upsell contrib: (assumes you are using Image Cache)

($relproduct is an object returned from a db_query)

<?php
(($relProduct->field_image_cache) ? '<img src="' . base_path() . $conf['file_directory_path'] . '/imagecache/thumbnail/'. $relProduct->field_image_cache[0]['filepath'] . '" />' : '')
?>

Basically it's just checking for the image_cache field, and if image_cache exists, then it finds the file_directory path from your base_path (usually /files) and then grabs the filepath for your field_image_cache field in the database. I'm pretty sure that "thumbnail" is a default imagecache (or Ubercart?) preset but I could be wrong. Try messing with that code, it should do what you need.

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 70
Joined: 04/14/2008

Beauty. That looks like precisely what I need.

I appreciate the help!