Removed a line from config.php
[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
11 $PATH_INFO = $file;
12 }
13
f9903ed0 14 if (!$PATH_INFO) {
3f8247c2 15 error("This script DEPENDS on PATH_INFO being available. Read the README.");
f9903ed0 16 }
17
55b8ac31 18 if (! $args = get_slash_arguments()) {
19 error("No valid arguments supplied");
20 }
21
f9903ed0 22 $numargs = count($args);
f9903ed0 23 $courseid = (integer)$args[0];
24
21ddaf60 25 $course = get_record("course", "id", $courseid);
26
27 if ($course->category) {
f9903ed0 28 require_login($courseid);
29 }
30
21ddaf60 31 // it's OK to get here if no course was specified
32
f9903ed0 33 $pathname = "$CFG->dataroot$PATH_INFO";
34 $filename = $args[$numargs-1];
35
36 $mimetype = mimeinfo("type", $filename);
37
38 if (file_exists($pathname)) {
39 $lastmodified = filemtime($pathname);
40
41 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
42 header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
43 header("Cache-control: max_age = $lifetime"); // a day
44 header("Pragma: ");
5be2f47c 45 header("Content-disposition: inline; filename=$filename");
46 header("Content-length: ".filesize($pathname));
f9903ed0 47 header("Content-type: $mimetype");
48 readfile("$pathname");
49 } else {
21ddaf60 50 error("Sorry, but the file you are looking for was not found", "course/view.php?id=$courseid");
f9903ed0 51 }
52
53 exit;
54?>