Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After uploading a file to Drupal 7 via a form, how to get the file's path?

I have a form that uploads a file to my Drupal installation. I want to store the path to that file in a table. How do I get the path to the recently uploaded file? I tried

$f = file_load($form_state['values']['field_file']);
$f->uri;

But that's not working. Any clues?

like image 398
KerrM Avatar asked Nov 18 '11 12:11

KerrM


1 Answers

$f = file_load($form_state['values']['field_file']);
$url = file_create_url($f->uri);

The URI is the public:// private:// etc which Drupal uses internally. To convert it use file_create_url(); Ideally you should still store the URI and then use the file_create_url() when rendering.

like image 81
Ben Swinburne Avatar answered Sep 23 '22 02:09

Ben Swinburne