Tidied up the front page. Added 'editing' switch and normal footer
[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);
16
17 $courseid = (integer)$args[0];
18
19 if ($courseid > 0) {
20 require_login($courseid);
21 }
22
23 $pathname = "$CFG->dataroot$PATH_INFO";
24 $filename = $args[$numargs-1];
25
26 $mimetype = mimeinfo("type", $filename);
27
28 if (file_exists($pathname)) {
29 $lastmodified = filemtime($pathname);
30
31 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
32 header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
33 header("Cache-control: max_age = $lifetime"); // a day
34 header("Pragma: ");
35 header("Content-Length: ".filesize($pathname));
36 header("Content-type: $mimetype");
37 readfile("$pathname");
38 } else {
39 error("Sorry, but the file you are looking for was not found", "/course/view.php?id=$courseid");
40 }
41
42 exit;
43?>