2 // This function fetches files from the data directory
3 // Syntax: file.php/courseid/dir/.../dir/filename.ext
5 require_once("config.php");
6 require_once("files/mimetypes.php");
10 if (isset($file)) { // workaround for situations where / syntax doesn't work
13 $pathinfo = get_slash_arguments("file.php");
17 error("No file parameters!");
20 if (! $args = parse_slash_arguments($pathinfo)) {
21 error("No valid arguments supplied");
24 $numargs = count($args);
25 $courseid = (integer)$args[0];
27 $course = get_record("course", "id", $courseid);
29 if ($course->category
) {
30 require_login($courseid);
33 // it's OK to get here if no course was specified
35 $pathname = "$CFG->dataroot$pathinfo";
36 $filename = $args[$numargs-1];
38 $mimetype = mimeinfo("type", $filename);
40 if (file_exists($pathname)) {
41 $lastmodified = filemtime($pathname);
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
47 header("Content-disposition: inline; filename=$filename");
48 header("Content-length: ".filesize($pathname));
49 header("Content-type: $mimetype");
50 readfile("$pathname");
52 error("Sorry, but the file you are looking for was not found ($pathname)", "course/view.php?id=$courseid");