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