I was programming something in moodle web-application and was looking into retrieving the path of the user profile images.
I assumed I could find the path somewhere in the database but I only got to mdl_user.picture and mdl_user.imagealt, so practically I know who has uploaded a picture but can't get to which picture he/she uploaded.
Is there a way to get it from the database?
Thanks for your help,
OM
To change your picture, log into Moodle then click your name in the top right of the screen → Profile → Edit Profile (from the gear icon) and scroll down to the User Picture area. Drag your desired image file into the New Picture box.
To upload a new profile picture, click the Upload a Picture tab [1], then click the choose a picture link [2]. You can also drag a picture from your desktop and drop it into the uploader.
in moodle 2.0 you can use this
global $USER,$PAGE;
$user_picture=new user_picture($USER);
$src=$user_picture->get_url($PAGE);
If you want the image tag you can use print_user_picture() and pass the user object that you got from the database. You can also specify the size of the image. So to print the full size user picture for the current user you could do
global $USER, $COURSE;
print_user_picture($USER, $COURSE->id, null, true);
Otherwise if you need just the url you have do do something like this
require_once($CFG->libdir.'/filelib.php');
$size = array('large' => 'f1', 'small' => 'f2');
$src = false;
if ($user->picture) {
$src = get_file_url($user->id.'/'.$size['large'].'.jpg', null, 'user');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With