2 // This function fetches user pictures from the data directory
3 // Syntax: pix.php/userid/f1.jpg or pix.php/userid/f2.jpg
4 // OR: ?file=userid/f1.jpg or ?file=userid/f2.jpg
6 require_once('../config.php');
7 require_once($CFG->libdir
.'/filelib.php');
9 if (!empty($CFG->forcelogin
) and !isloggedin()) {
10 // protect images if login required and not logged in;
11 // do not use require_login() because it is expensive and not suitable here anyway
12 redirect($CFG->pixpath
.'/u/f1.png');
15 // disable moodle specific debug messages
18 $relativepath = get_file_argument('pix.php');
20 $args = explode('/', trim($relativepath, '/'));
22 if (count($args) == 2) {
23 $userid = (integer)$args[0];
24 // do not serve images of deleted users
25 if ($user = get_record('user', 'id', $userid, 'deleted', 0, 'picture', 1)) {
27 $pathname = make_user_directory($userid, true) . "/$image";
28 if (file_exists($pathname) and !is_dir($pathname)) {
29 send_file($pathname, $image);
34 // picture was deleted - use default instead
35 redirect($CFG->pixpath
.'/u/f1.png');