New translation strings and new file chat.php added.
[moodle.git] / file.php
blobec4b6c246ef09d6dd39514f02f82d556266b99b5
1 <?PHP // $Id$
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");
8 $lifetime = 86400;
10 if (isset($file)) { // workaround for situations where / syntax doesn't work
11 $pathinfo = $file;
12 } else {
13 $pathinfo = get_slash_arguments("file.php");
16 if (!$pathinfo) {
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
46 header("Pragma: ");
47 header("Content-disposition: inline; filename=$filename");
48 header("Content-length: ".filesize($pathname));
49 header("Content-type: $mimetype");
50 readfile("$pathname");
51 } else {
52 error("Sorry, but the file you are looking for was not found ($pathname)", "course/view.php?id=$courseid");
55 exit;