Latest ADOdb version (thanks Eloy)
[moodle.git] / user / pix.php
blob979214893864c579f65d6471748387c7f33e8d42
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 $nomoodlecookie = true; // Because it interferes with caching
8 require_once("../config.php");
10 $lifetime = 86400;
12 if (isset($file)) { // workaround for situations where / syntax doesn't work
13 $pathinfo = $file;
15 } else {
16 $pathinfo = get_slash_arguments("pix.php");
19 if (! $args = parse_slash_arguments($pathinfo)) {
20 error("No valid arguments supplied");
23 $numargs = count($args);
25 if ($numargs == 2) {
26 $userid = (integer)$args[0];
27 $image = $args[1];
28 $pathname = "$CFG->dataroot/users/$userid/$image";
29 $filetype = "image/jpeg";
30 } else {
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
41 header("Pragma: ");
42 header("Content-disposition: inline; filename=$image");
43 header("Content-length: ".filesize($pathname));
44 header("Content-type: $filetype");
45 readfile("$pathname");
48 exit;