Hi,
I'm trying to add picture to user profile.
I have url to the picture thats need to be upload to the user.
I need to do it programmatically ( from the upload users csv ).
How can I do it?
Thanks,
Lital
We do that in our authentication plugin (as we user our own SSO plugin).
Its perhaps not the best place for it but it works and means the first time a user logs in their profile picture is there.
What we do is CURL in the image from a URL and store it in a temporary directory which is required to then use Moodles function to crop the image.
Once we have the image in place we simply call:
process_new_icon($context, 'user', 'icon', 0, $filepath);
That function will crop the image and put it in the users profile for you.
yes you can add user pictures through programmatically.
old Code :$src = $userpicture->get_url($this->page, $this);
New CODE :
$user_picture_url = "select * from {user} where id = ".$userpic;
$module_course = $DB->get_records_sql($user_picture_url);
foreach($module_course AS $rec){
$url_picture=$rec->url_picture;
}
if($url_picture != NULL && $user->picture == 0)
{
if (getimagesize($url_picture) !== false) {
//echo 'display image';
$src = $url_picture;
}else{
$src = $userpicture->get_url($this->page, $this);
}
}
Praveen
Hi!
You need to use php function copy to move your image from the external source to your (tempotary) folder, and then you need to use Moodle function process_new_icon
You can read about upload user profiles images at the article here: http://lms-service.org/blog/news/lenauth-updated-version-1-1-0/
Thank you all!