2 // This function fetches files from the data directory
3 // Syntax: file.php/courseid/dir/.../dir/filename.ext
6 require("files/mimetypes.php");
10 if (isset($file)) { // workaround for situations where / syntax doesn't work
15 error("This script DEPENDS on PATH_INFO being available. Read the README.");
18 if (! $args = get_slash_arguments()) {
19 error("No valid arguments supplied");
22 $numargs = count($args);
23 $courseid = (integer)$args[0];
25 $course = get_record("course", "id", $courseid);
27 if ($course->category) {
28 require_login($courseid);
31 // it's OK to get here if no course was specified
33 $pathname = "$CFG->dataroot$PATH_INFO";
34 $filename = $args[$numargs-1];
36 $mimetype = mimeinfo("type", $filename);
38 if (file_exists($pathname)) {
39 $lastmodified = filemtime($pathname);
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
45 header("Content-disposition: inline; filename=$filename");
46 header("Content-length: ".filesize($pathname));
47 header("Content-type: $mimetype");
48 readfile("$pathname");
50 error("Sorry, but the file you are looking for was not found", "course/view.php?id=$courseid");