Better error message when invalid arguments are supplied.
[moodle.git] / user / pix.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2 // This function fetches user pictures from the data directory
2447921f 3 // Syntax: pix.php/userid/f1.jpg or pix.php/userid/f2.jpg
4 // OR: ?file=userid/f1.jpg or ?file=userid/f2.jpg
f9903ed0 5
6 require("../config.php");
7
8 $lifetime = 86400;
9
2447921f 10 if (isset($file)) {
11 $PATH_INFO = $file;
12
13 } else if (!$PATH_INFO) {
14 $PATH_INFO = ""; // Will just show default picture
f9903ed0 15 }
16
55b8ac31 17 if (! $args = get_slash_arguments()) {
18 error("No valid arguments supplied");
19 }
20
f9903ed0 21 $numargs = count($args);
22
23 if ($numargs == 2) {
24 $userid = (integer)$args[0];
25 $image = $args[1];
2447921f 26 $pathname = "$CFG->dataroot/users/$userid/$image";
f9903ed0 27 } else {
2447921f 28 $pathname = "$CFG->dirroot/user/default/f1.jpg";
f9903ed0 29 }
30
f9903ed0 31 $lastmodified = filemtime($pathname);
32
33 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
34 header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
35 header("Cache-control: max_age = $lifetime"); // a day
36 header("Pragma: ");
5be2f47c 37 header("Content-disposition: inline; filename=$image");
38 header("Content-length: ".filesize($pathname));
f9903ed0 39 header("Content-type: image/jpeg");
40 readfile("$pathname");
41
42 exit;
43?>