i am trying to fetch loged in users photo to make a welcome block. i have applied a code which is not working

$userphoto = $user->picture;

so what to do to fetching user photo or image URL, any idea?

3 Answers 3


The picture property of the user entity is the file ID (a reference to the fid column in the file_managed table).

You can load the file explicitly with file_load() like so:

$file = file_load($user->picture);

And render it to an image using theme_image():

$image = theme('image', array(
  'path' => $file->uri,
  'alt' => 'Some alt',
  // etc...

Alternatively you could dispense with the above and just use the handy theme_user_picture() function:

$image = theme('user_picture', array('account' => $account));
  • thanks for that, but is it possible to get the image path(URL)?
    – rakibtg
    Commented Jul 16, 2012 at 15:02
  • 1
    Sure, just run $url = file_create_url($file->uri);, that'll give you a web-accessible URL as opposed to a stream URI
    – Clive
    Commented Jul 16, 2012 at 15:03
  • oh is it my mistakes, it shows only home page address with this error message: ` Notice: Undefined variable: file in eval() (line 4 of /home/busines/public_html/modules/php/php.module(80) : eval()'d code). Notice: Trying to get property of non-object in eval() (line 4 of /home/busines/public_html/modules/php/php.module(80) : eval()'d code). `
    – rakibtg
    Commented Jul 16, 2012 at 15:15
  • Have you put $file = file_load($user->picture); before you run that line?
    – Clive
    Commented Jul 16, 2012 at 15:15
  • Thank you so much Clive .. works great now, i will write again if any problem happens :)
    – rakibtg
    Commented Jul 16, 2012 at 15:18

Maybe it is helpful to render with a image styles


second param is a drupal's internal file path like 'public://images/myimage.png'


You can try the following:

$user = user_load($view->result[$key]->uid);
$filepath = $user->picture->uri;
$picture_url = file_create_url($filepath);

This will give you the user's picture url.

Your Answer

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

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