【问题标题】:Path to profile picture in Moodle?Moodle中个人资料图片的路径?
【发布时间】:2011-07-27 06:24:10
【问题描述】:

我正在 moodle web 应用程序中编写一些东西,并且正在研究检索用户个人资料图像的路径。

我以为我可以在数据库中的某处找到路径,但我只找到了 mdl_user.picture 和 mdl_user.imagealt,所以实际上我知道谁上传了一张图片,但无法找到他/她上传的哪张图片。

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

感谢您的帮助,

OM

【问题讨论】:

标签: php database moodle


【解决方案1】:

如果你想要图像标签,你可以使用 print_user_picture() 并传递你从数据库中获得的用户对象。您还可以指定图像的大小。因此,要为当前用户打印完整尺寸的用户图片,您可以这样做

global $USER, $COURSE;

print_user_picture($USER, $COURSE->id, null, true);

否则,如果您只需要您拥有的网址,请执行以下操作

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

【讨论】:

  • 我在moodledata下添加了一个文件夹,例如PDFdata如何访问它。我尝试了这种方法,它显示“无效的课程ID”..请帮助
【解决方案2】:

在moodle 2.0中你可以使用这个

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

【讨论】:

    【解决方案3】:

    这个在 3.4 版本中适用于我

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

    【讨论】:

      【解决方案4】:

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

      您需要先找到示例中用户 id (3) 的实例 ID。

      然后您需要在文件表中搜索实例 ID /user/icon/f/f[1-3].[jpg|png] 的哈希值

      此查询将按大小顺序给出所有文件,其中最大的文件在前。

      第一列 file_path 将是相对于您服务器上的 moodle 文件的文件路径。查看 config.php 以获取 $CFG-&gt;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
      

      【讨论】:

        【解决方案5】:

        要获取用户个人资料图片,您可以使用以下路径:

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

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

        【讨论】:

        • 这是不正确的,23 是上下文 id,而不是用户 id = 3 加上数字 2。
        猜你喜欢
        • 2017-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多