How do I get the public url of a file from the uri or filename I'm using php from with a view (Views PHP) I'm trying to extract the real url of a file from a file reference. I am able to get the the uri of the file and or the filename. What drupal function can I use to get thee actual public URL of the file?.

$videouri = db_query('SELECT filename FROM `file_managed` WHERE fid = ' . $nidvideo)-&gt;fetchColumn();
//drupal_set_message('&lt;pre&gt;'. print_r($videourl, TRUE) .'&lt;/pre&gt;');
$realpath = drupal_realpath($videouri);
$videourl = file_create_url($realpath);
return($videourl);
What do you mean by &quot;public URL&quot; exactly ?
file_create_url() can give the absolute URL to the image out of the box.
$videouri = db_query('SELECT uri FROM {file_managed} WHERE fid = :nidvideo', array(':nidvideo' =&gt; $nidvideo))-&gt;fetchColumn();
//drupal_set_message('&lt;pre&gt;'. print_r($videourl, TRUE) .'&lt;/pre&gt;');
$videourl = file_create_url($videouri);

file_create_url() expects a valid uri. drupal_realpath() gives the server path which does not work.
I also changed your database query to avoid any SQL injection vulnerable.