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 $pathinfo = urldecode($pathinfo);
22 if (! $args = parse_slash_arguments($pathinfo)) {
23 error("No valid arguments supplied");
26 $numargs = count($args);
27 $courseid = (integer)$args[0];
29 $course = get_record("course", "id", $courseid);
31 if ($course->category
) {
32 require_login($courseid);
35 // it's OK to get here if no course was specified
37 $pathname = "$CFG->dataroot$pathinfo";
38 $filename = $args[$numargs-1];
40 $mimetype = mimeinfo("type", $filename);
42 if (file_exists($pathname)) {
43 $lastmodified = filemtime($pathname);
45 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
46 header("Expires: " . gmdate("D, d M Y H:i:s", time() +
$lifetime) . " GMT");
47 header("Cache-control: max_age = $lifetime"); // a day
49 header("Content-disposition: inline; filename=$filename");
50 header("Content-length: ".filesize($pathname));
51 header("Content-type: $mimetype");
52 readfile("$pathname");
54 error("Sorry, but the file you are looking for was not found ($pathname)", "course/view.php?id=$courseid");