weekly release 1.9.13+
[moodle.git] / user / pix.php
blobd37d18b093973eac7ad0cdd2683b51964411e391
1 <?PHP // $Id$
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
16 disable_debugging();
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)) {
26 $image = $args[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');