6

I need to load an image that's uploaded to the public folder from within a module

In the module itself:

function mymodule_dashboard() {
   GLOBAL $user;
   $profile = profile2_load_by_user($user->uid, 'personal_information');
   $data['avatar'] = $profile->field_picture['und'][0]['uri'];

In my dashboard.tpl.php:

<img src="<?php echo $data['avatar']; ?>" />

The rendered content:

<img src="public://image.jpg">

I can pull the image name and build the path myself, but I'm looking for a way to actually take advantage of this public folder business

10

You're looking for the file_create_url() function:

Creates a web-accessible URL for a stream to an external or local file.

e.g.

$data['avatar'] = file_create_url($profile->field_picture['und'][0]['uri']);
| improve this answer | |
  • aha! so THAT's how that's supposed to work.. :p perfect. – Damon May 29 '12 at 19:46

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.