Php Moodle中配置文件图片的路径?

Php Moodle中配置文件图片的路径?,php,database,moodle,Php,Database,Moodle,我在moodle web应用程序中编写了一些东西,并正在研究如何检索用户配置文件图像的路径 我假设我可以在数据库的某个地方找到路径,但我只找到了mdl_user.picture和mdl_user.imagealt,所以实际上我知道谁上传了图片,但无法找到他/她上传的图片 有没有办法从数据库中获取它 谢谢你的帮助 OM如果需要图像标记,可以使用print\u user\u picture()并传递从数据库获得的用户对象。您还可以指定图像的大小。因此,要打印当前用户的全尺寸用户图片,您可以执行以下操

我在moodle web应用程序中编写了一些东西,并正在研究如何检索用户配置文件图像的路径

我假设我可以在数据库的某个地方找到路径,但我只找到了mdl_user.picture和mdl_user.imagealt,所以实际上我知道谁上传了图片,但无法找到他/她上传的图片

有没有办法从数据库中获取它

谢谢你的帮助


OM

如果需要图像标记,可以使用print\u user\u picture()并传递从数据库获得的用户对象。您还可以指定图像的大小。因此,要打印当前用户的全尺寸用户图片,您可以执行以下操作

global $USER, $COURSE;

print_user_picture($USER, $COURSE->id, null, true);
否则,如果您需要的只是url,您可以这样做

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

在moodle 2.0中,您可以使用

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

要获取用户配置文件pic,只需使用以下路径:

注意:使用的userid=3并附加数字2


路径:

这一条在3.4版本中适用于我

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

OP要求从数据库获取此信息,其他海报给出了如何使用PHP从moodle获取此信息的提示-但如果您无法访问moodle代码,这就是方法

在示例中,首先需要找到用户ID(3)的实例ID

然后您需要在files表中搜索实例ID/user/icon/f/f[1-3].[jpg|png]的散列

此查询将按大小顺序给出所有文件,其中最大的文件位于第一位

第一列文件路径是相对于服务器上moodle文件的文件路径。有关其位置,请参见config.php中的
$CFG->dataroot

select @instanceID := id instance_id
from mdl_context where contextlevel = 30 and instanceid = 3; # instanceid = 3 is user id 3
select @instanceID; # check it is present.
;
SELECT concat(left(f.contenthash,2),"/",substring(f.contenthash,3,2),"/",f.contenthash) file_path, f.pathnamehash, timecreated, filename, f.*
FROM mdl_files f
LEFT JOIN mdl_files_reference r ON f.referencefileid = r.id
WHERE f.pathnamehash in(
    sha1(concat("/",@instanceID,"/user/icon/0/f1.jpg")),
    sha1(concat("/",@instanceID,"/user/icon/0/f2.jpg")),
    sha1(concat("/",@instanceID,"/user/icon/0/f3.jpg")), 
    sha1(concat("/",@instanceID,"/user/icon/0/f1.png")),
    sha1(concat("/",@instanceID,"/user/icon/0/f2.png")),
    sha1(concat("/",@instanceID,"/user/icon/0/f3.png")))
order by timecreated desc, filename desc

我已经为Moodle用户和开发人员创建了一个Stack Exchange网站的提案。这个问题非常适合它,而不是堆栈溢出。我在moodledata下添加了一个文件夹,如PDFdata如何访问它。。我试过这个方法,上面写着“无效的课程Id”。。请帮助这是不正确的,23是上下文id,而不是附加数字2的用户id=3。