Path to profile picture in Moodle?

前提是你 提交于 2019-12-09 13:48:12

问题


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


回答1:


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');
}



回答2:


in moodle 2.0 you can use this

global $USER,$PAGE; 
$user_picture=new user_picture($USER);
$src=$user_picture->get_url($PAGE);



回答3:


To get the User profile pic simply you can use the following path:

NOTE: used userid = 3 and appended with number 2

Path : http://moodleservername/moodle/pluginfile.php/23/user/icon/clean/f1




回答4:


this one works for me in 3.4 version

<?php echo new moodle_url('/user/pix.php/'.$USER->id.'/f1.jpg')?>


来源:https://stackoverflow.com/questions/6840187/path-to-profile-picture-in-moodle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!