Displays all user pictures on one page.
[moodle.git] / file.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2 // This function fetches files from the data directory
3 // Syntax: file.php/courseid/dir/.../dir/filename.ext
4
b0e3a925 5 require_once("config.php");
6 require_once("files/mimetypes.php");
f9903ed0 7
8 $lifetime = 86400;
9
3f8247c2 10 if (isset($file)) { // workaround for situations where / syntax doesn't work
6ed3da1d 11 $pathinfo = $file;
12 } else {
13 $pathinfo = get_slash_arguments("file.php");
3f8247c2 14 }
15
6ed3da1d 16 if (!$pathinfo) {
17 error("No file parameters!");
f9903ed0 18 }
19
6ed3da1d 20 if (! $args = parse_slash_arguments($pathinfo)) {
55b8ac31 21 error("No valid arguments supplied");
22 }
23
f9903ed0 24 $numargs = count($args);
f9903ed0 25 $courseid = (integer)$args[0];
26
21ddaf60 27 $course = get_record("course", "id", $courseid);
28
29 if ($course->category) {
f9903ed0 30 require_login($courseid);
31 }
32
21ddaf60 33 // it's OK to get here if no course was specified
34
9277dbd4 35 $pathname = "$CFG->dataroot$pathinfo";
f9903ed0 36 $filename = $args[$numargs-1];
37
38 $mimetype = mimeinfo("type", $filename);
39
40 if (file_exists($pathname)) {
41 $lastmodified = filemtime($pathname);
42
43 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
44 header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
45 header("Cache-control: max_age = $lifetime"); // a day
46 header("Pragma: ");
5be2f47c 47 header("Content-disposition: inline; filename=$filename");
48 header("Content-length: ".filesize($pathname));
f9903ed0 49 header("Content-type: $mimetype");
50 readfile("$pathname");
51 } else {
dcde9f02 52 error("Sorry, but the file you are looking for was not found ($pathname)", "course/view.php?id=$courseid");
f9903ed0 53 }
54
55 exit;
56?>