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 $nomoodlecookie = true; // Because it interferes with caching
8 require_once("../config.php");
12 if (isset($file)) { // workaround for situations where / syntax doesn't work
16 $pathinfo = get_slash_arguments("pix.php");
19 if (! $args = parse_slash_arguments($pathinfo)) {
20 error("No valid arguments supplied");
23 $numargs = count($args);
26 $userid = (integer)$args[0];
28 $pathname = "$CFG->dataroot/users/$userid/$image";
29 $filetype = "image/jpeg";
31 $pathname = "$CFG->dirroot/pix/u/f1.png";
32 $filetype = "image/png";
35 $lastmodified = filemtime($pathname);
37 if (file_exists($pathname)) {
38 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
39 header("Expires: " . gmdate("D, d M Y H:i:s", time() +
$lifetime) . " GMT");
40 header("Cache-control: max_age = $lifetime"); // a day
42 header("Content-disposition: inline; filename=$image");
43 header("Content-length: ".filesize($pathname));
44 header("Content-type: $filetype");
45 readfile("$pathname");