By cumhur on
Hi,
How can I load user picture programmatically ı searched at google ı find this code but ı can t load user picture in Drupal 7 help please
$newUser = array(
'name' => 'username',
'pass' => 'password', // note: do not md5 the password
'mail' => 'email address',
'status' => 1,
'init' => 'email address'
);
user_save(null, $newUser);
// load user object
$existingUser = user_load('USERID');
// update some user property
$existingUser->some_property = 'blah';
// save existing user
user_save((object) array('uid' => $existingUser->uid), (array) $existingUser);
// load user object
$existingUser = user_load('USERID');
// create an array of properties to update
$edit = array(
'profile_first_name' => 'Eric'
);
// save existing user
user_save(
(object) array('uid' => $existingUser->uid),
$edit,
'Personal Information' // category
);
Comments
Re: Upload user picture programmatically
I would suggest that you install the Devel module (if you haven't already) and look at the data that Drupal is expecting under the user's "Devel -> Dev load" tab.
Hope that helps!
Steve
Re: Upload user picture programmatically
Thank you Steve I will try
Upload user picture programmatically
I try but I couldn t find any solution
Where can find a sample code for programaticly upload user picture?
thanks
A Hackish Solution...
One way to programmatically save user pictures (if that's what you're trying to do) is after user_save(), manually insert the file into the {users} table.
I've had no end of trouble with $account->picture, probably stemming from my ignorance of the File API. It seems that $account->picture is supposed to be a file id (fid), but perhaps you're supposed to pass a complete file object? I've seen people do things like $account->picture->uri, which makes me believe that perhaps it's a complete file object that you're supposed to pass in to programmatically create it. If anyone can give a definitive answer on this, I'd be much obliged.
Note: Code from facebook_oauth module, thanks to quicksketch and others.
--Alec
Tandem
An example to add user picture programmatically
Hi! Recently I was working on this problem. I have a solution.
Here you can find an example how to add a picture to the user account programmatically:
http://d.danylevskyi.com/node/7
Thanks!
Thank you, your code snippet was just what I needed. Terrific!
danylevskyi's solution
Here's danylevskyi's solution from the (now expired) link he provided:
Attaching User Picture from Form