Path to Images for Content Type In a custom module I'm trying to display results from mysql DB based on items users selected in a form. One of the fields in the content type I'd like to display is an image associated with the node. This image appears to be housed in the table 'file_managed' in a field called 'filename' - or at least that's where the NAME of the file is located. I'm able to retrieve that field fine using SQL and joins and when I echo the result it shows the following (for example):

nameoffile.png


So I tried calling that with php using:

$icon = $row['filename'];
echo $icon; // works fine

$output .= '&lt;img src="' . $icon . '" /&gt;';


And it just shows a blank image icon (not the image nameoffile.png). 

So then I think well I must have the path wrong. So I dragged the image icon from the search results page (where it displays just fine) into a new tab and this is the URL I get:

http://pf.dev/sites/default/files/styles/thumbnail/public/PPP_CCYCL_CLP_ChrevonCycle_A_8Red.png


But of course I don't want to use an absolute path, esp. since this is on the dev. server. 

So my question is this: how do I find the paths to my content type images so I can display them correctly in my custom module?
There are a couple of things you can do. First, instead of grabbing the filename field from the {file_managed} table, you'll want to grab the uri.

Then you can use file_create_url() to generate a url to the original file:

$icon = file_create_url($row['uri']);
$output .= '&lt;img src="' . $icon . '" /&gt;';


Or if you want to run the image through an image style, you can use image_style_url() (you'll need to know the machine name of the image style)

$icon = image_style_url('image_style', $row['uri']);
$output .= '&lt;img src="' . $icon . '" /&gt;';