0

I have a problem Accessing the file path of an uploaded image. I'm trying to create a custom Carousel and build it up in a Drupal Block. I'm pulling the array created from the view of the content type like so:

$slides = views_get_view_result('slide');

foreach ($slides as $slide) {
    echo $slide->_field_data['nid']['entity']->field_slide_image['und'][0]['uri'];
}

My problem is that URI prints out "public://someimage.jpg" instead of "someimage.jpg" or "sites/all/images/someimage.jpg." I know I could do a string replace on this, but Drupal must have a way of getting the right file path to the image. Any suggestions?

1 Answer 1

1

You can use file_create_url($uri) which will generate an absolute URL (including $base_url which contains your server domain name).

print file_create_url('public://someimage.jpg'); will generate something like http://localhost/sites/default/files/someimage.jpg if your website is installed in localhost and your files are located in the default directory.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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