It has been a few days I'm trying to get the uploaded file urls in drupal7 (using default file filed in drupal content type) from a view. I must get this url in page which a view is embedded inside it, this view shows 10 items of its content type per page, how can I get the url of filefield?

should I use preprocess function or any thing else?

I have tried many ways suggested in many websites but I have failed. is there any straight forward solution?


It's not really clear what you mean by 'access' in this context, but if you're looking to get the details for a file uploaded through a file field:

$node = node_load(1);
if ( ($field_items = field_get_items('node', $node, 'field_file')) ) {
  $file = file_load($field_items[0]['fid']);

  $uri = $file->uri;
  $external_url = file_create_url($uri);

Or to grab the external URL directly with an EntityMetadataWrapper:

$node = node_load(1);
$wrapper = entity_metadata_wrapper('node', $node);
$external_url = $wrapper->field_files[0]->file->url->value();
  • where should I use this code? – M a m a D Oct 7 '13 at 14:34
  • Wherever you want/need to use it, there's no specific place for it to go – Clive Oct 7 '13 at 14:35
  • can I use it in views-view-field template function ? – M a m a D Oct 7 '13 at 14:36
  • Well don't put it in the template file (it'll cause havoc with caching), but in a preprocess function, sure – Clive Oct 7 '13 at 14:36
  • 1
    I'm afraid your deadlines are irrelevant here - this is a Q+A site, the mission is to build a site full of high quality content, not to do people's job for them within a certain time constraint. I disagree that your question is clear; I can't understand it, and I've been developing in Drupal for over 3 years and speaking English for over 30. You haven't describe the context in which you need to 'get' the value, what you need to do with it, or shown that you've made any effort to solve the problem yourself. I'd advise improving the question considerably, but that is your prerogative, of course. – Clive Oct 7 '13 at 15:02

change the Formatter of file to URL to file in views administrative menu and then by this code strip_tags($fields['field_file']->content); you will get the url

  • 1
    This is right. But in order for the 'URL to file' option to appear, you must enable the image_url_formatter module (drupal.org/project/image_url_formatter) – Druvision Jan 16 '14 at 17:10
  • @Druvision I didnt enable this module and it still working – M a m a D Jan 17 '14 at 5:08
  • In the end I did enable this module and it's still not working. Too many modules. – Druvision Jan 17 '14 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.