Programmtically add image to custom image field User I can't figure out how to add image to a custom image field on a sepcific user.

    $f = file_save_data($user['thumbnailphoto'][0], 'private://profile/'. $data['name'] .'.jpg', FILE_EXISTS_REPLACE);
    $fid = $f-&gt;fid;

    //Add to virtual map 'Profile images'
    $file_entity = file_load($fid);
    $file_entity-&gt;status = 1;
    $file_entity-&gt;field_folder['und'][0]['tid'] = 180;
    file_save($file_entity);

    $user = user_load(334);

    $details['field_profile_picture'] = array(
                                        'und' =&gt; array( 
                                            0 =&gt; array(
                                            'fid' =&gt; $fid,
    )));

    $u = user_save($user, $details);


But nothing get saved? Field_profile_picture is just an image field.

Thx!
In Drupal 7 you can use system_retrieve_file()


  system_retrieve_file : This function will download a file from a remote source, copy it from temp to a specified destination and optionally save it to
  the file_managed table if you want it to be managed.



  $usr_info = user_load(334); //load user object
  if (!empty($usr_info)) {//assign only if user exist
    $image_url = 'http://g-raph.be/sites/all/themes/g_raph_/images/image03.jpg'; //image URL to save. If image already saved in the drupal system then get the file ID(fid)
    //I have used picture folder to store images using image field settings
    $file_info = system_retrieve_file($image_url, 'public://pictures/', TRUE, FILE_EXISTS_REPLACE); //storing image inside picture folder
    if ($file_info->fid) {//if fid exist then image is saved from URL.
      //$usr_info->picture = file_load($file_info->fid); //for default profile pic
      $usr_info->field_profile_picture[LANGUAGE_NONE][0]['fid'] = $file_info->fid; //for custom profile pic
    }
    user_save($usr_info);
  }