translated & polished some.
[moodle.git] / file.php
blob97052b04e16fbdc490e9fdf72eda5776ad776f97
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 $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
48 header("Pragma: ");
49 header("Content-disposition: inline; filename=$filename");
50 header("Content-length: ".filesize($pathname));
51 header("Content-type: $mimetype");
52 readfile("$pathname");
53 } else {
54 error("Sorry, but the file you are looking for was not found ($pathname)", "course/view.php?id=$courseid");
57 exit;