Fixed firstname lastname to call to fullname function
[moodle.git] / file.php
CommitLineData
822a1063 1<?php
2
3 /**
4 * file.php - Used to fetch file from the data directory
5 *
6 * This script file fetches files from the data directory (dataroot)<br>
7 * Syntax: file.php/courseid/dir/.../dir/filename.ext
8 *
9 * @uses $CFG
10 * @uses FORMAT_HTML
11 * @uses FORMAT_MOODLE
12 * @author Martin Dougiamas
13 * @version $Id$
14 * @package moodlecore
15 */
16
17 require_once('config.php');
18 require_once('files/mimetypes.php');
f9903ed0 19
66e5f959 20 if (empty($CFG->filelifetime)) {
21 $CFG->filelifetime = 86400; /// Seconds for files to remain in caches
22 }
f9903ed0 23
3f8247c2 24 if (isset($file)) { // workaround for situations where / syntax doesn't work
6ed3da1d 25 $pathinfo = $file;
26 } else {
822a1063 27 $pathinfo = get_slash_arguments('file.php');
3f8247c2 28 }
29
6ed3da1d 30 if (!$pathinfo) {
822a1063 31 error('No file parameters!');
f9903ed0 32 }
33
ae67d9cd 34 $pathinfo = urldecode($pathinfo);
35
6ed3da1d 36 if (! $args = parse_slash_arguments($pathinfo)) {
822a1063 37 error('No valid arguments supplied');
55b8ac31 38 }
39
f9903ed0 40 $numargs = count($args);
a4557331 41 if ($numargs < 2 or empty($args[1])) {
822a1063 42 error('No valid arguments supplied');
a4557331 43 }
44
f9903ed0 45 $courseid = (integer)$args[0];
46
822a1063 47 if (!$course = get_record('course', 'id', $courseid)) { // Course ID must be specified
48 error('Invalid course ID');
76112421 49 }
21ddaf60 50
51 if ($course->category) {
f9903ed0 52 require_login($courseid);
f57cd38b 53 } else if ($CFG->forcelogin) {
54 require_login();
f9903ed0 55 }
56
822a1063 57 $pathname = $CFG->dataroot . $pathinfo;
58 if ($pathargs = explode('?', $pathname)) {
d45bd055 59 $pathname = $pathargs[0]; // Only keep what's before the '?'
60 }
f9903ed0 61 $filename = $args[$numargs-1];
822a1063 62 if ($fileargs = explode('?', $filename)) {
d45bd055 63 $filename = $fileargs[0]; // Only keep what's before the '?'
64 }
f9903ed0 65
f9903ed0 66 if (file_exists($pathname)) {
67 $lastmodified = filemtime($pathname);
822a1063 68 $mimetype = mimeinfo('type', $filename);
f9903ed0 69
822a1063 70 header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastmodified) . ' GMT');
71 header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $CFG->filelifetime) . ' GMT');
72 header('Cache-control: max_age = '. $CFG->filelifetime);
73 header('Pragma: ');
74 header('Content-disposition: inline; filename='. $filename);
b7a3d3b2 75
f0507011 76
3cf4ab97 77 if (empty($CFG->filteruploadedfiles)) {
822a1063 78 header('Content-length: '. filesize($pathname));
79 header('Content-type: '. $mimetype);
b7a3d3b2 80 readfile($pathname);
3cf4ab97 81
82 } else { /// Try and put the file through filters
822a1063 83 if ($mimetype == 'text/html') {
ee88d30b 84 $options->noclean = true;
85 $output = format_text(implode('', file($pathname)), FORMAT_HTML, $options, $courseid);
e5890e71 86
822a1063 87 header('Content-length: '. strlen($output));
88 header('Content-type: text/html');
e5890e71 89 echo $output;
3cf4ab97 90
822a1063 91 } else if ($mimetype == 'text/plain') {
3cf4ab97 92 $options->newlines = false;
ee88d30b 93 $options->noclean = true;
822a1063 94 $output = '<pre>'. format_text(implode('', file($pathname)), FORMAT_MOODLE, $options, $courseid) .'</pre>';
95 header('Content-length: '. strlen($output));
96 header('Content-type: text/html');
e5890e71 97 echo $output;
3cf4ab97 98
99 } else { /// Just send it out raw
822a1063 100 header('Content-length: '. filesize($pathname));
101 header('Content-type: '. $mimetype);
3cf4ab97 102 readfile($pathname);
103 }
f0507011 104 }
f9903ed0 105 } else {
822a1063 106 header('HTTP/1.0 404 not found');
107 error(get_string('filenotfound', 'error'), $CFG->wwwroot .'/course/view.php?id='. $courseid);
f9903ed0 108 }
109
110 exit;
822a1063 111?>