2 /*==============================================================
\r
4 ==============================================================
\r
5 This program is free software. You can redistribute it and/or
\r
6 modify it under the terms of the GNU General Public License
\r
7 as published by the Free Software Foundation.
\r
8 ==============================================================
\r
13 * @desc This script gets files like get.php, but without the course id as default folder
\r
14 * @author ATutor Authors
\r
15 * @copyright 2006, ATRC, University of Toronto
\r
16 * @link http://www.atutor.ca/
\r
20 define('AT_INCLUDE_PATH', '../../include/');
\r
21 if (isset($_GET['test'])) {
\r
22 header('HTTP/1.1 200 OK', TRUE);
\r
23 header('ATutor-Get: OK');
\r
28 require(AT_INCLUDE_PATH . 'vitals.inc.php');
\r
31 $mime['ez'] = 'application/andrew-inset';
\r
32 $mime['hqx'] = 'application/mac-binhex40';
\r
33 $mime['cpt'] = 'application/mac-compactpro';
\r
34 $mime['doc'] = 'application/msword';
\r
35 $mime['bin'] = 'application/octet-stream';
\r
36 $mime['dms'] = 'application/octet-stream';
\r
37 $mime['lha'] = 'application/octet-stream';
\r
38 $mime['lzh'] = 'application/octet-stream';
\r
39 $mime['exe'] = 'application/octet-stream';
\r
40 $mime['class'] = 'application/octet-stream';
\r
41 $mime['oda'] = 'application/oda';
\r
42 $mime['pdf'] = 'application/pdf';
\r
43 $mime['ai'] = 'application/postscript';
\r
44 $mime['eps'] = 'application/postscript';
\r
45 $mime['ps'] = 'application/postscript';
\r
46 $mime['rtf'] = 'application/rtf';
\r
47 $mime['smi'] = 'application/smil';
\r
48 $mime['smil'] = 'application/smil';
\r
49 $mime['mif'] = 'application/vnd.mif';
\r
50 $mime['ppt'] = 'application/vnd.ms-powerpoint';
\r
51 $mime['slc'] = 'application/vnd.wap.slc';
\r
52 $mime['sic'] = 'application/vnd.wap.sic';
\r
53 $mime['wmlc'] = 'application/vnd.wap.wmlc';
\r
54 $mime['wmlsc'] = 'application/vnd.wap.wmlscriptc';
\r
55 $mime['bcpio'] = 'application/x-bcpio';
\r
56 $mime['bz2'] = 'application/x-bzip2';
\r
57 $mime['vcd'] = 'application/x-cdlink';
\r
58 $mime['pgn'] = 'application/x-chess-pgn';
\r
59 $mime['cpio'] = 'application/x-cpio';
\r
60 $mime['csh'] = 'application/x-csh';
\r
61 $mime['dcr'] = 'application/x-director';
\r
62 $mime['dir'] = 'application/x-director';
\r
63 $mime['dxr'] = 'application/x-director';
\r
64 $mime['dvi'] = 'application/x-dvi';
\r
65 $mime['spl'] = 'application/x-futuresplash';
\r
66 $mime['gtar'] = 'application/x-gtar';
\r
67 $mime['gz'] = 'application/x-gzip';
\r
68 $mime['tgz'] = 'application/x-gzip';
\r
69 $mime['hdf'] = 'application/x-hdf';
\r
70 $mime['js'] = 'application/x-javascript';
\r
71 $mime['kwd'] = 'application/x-kword';
\r
72 $mime['kwt'] = 'application/x-kword';
\r
73 $mime['ksp'] = 'application/x-kspread';
\r
74 $mime['kpr'] = 'application/x-kpresenter';
\r
75 $mime['kpt'] = 'application/x-kpresenter';
\r
76 $mime['chrt'] = 'application/x-kchart';
\r
77 $mime['kil'] = 'application/x-killustrator';
\r
78 $mime['skp'] = 'application/x-koan';
\r
79 $mime['skd'] = 'application/x-koan';
\r
80 $mime['skt'] = 'application/x-koan';
\r
81 $mime['skm'] = 'application/x-koan';
\r
82 $mime['latex'] = 'application/x-latex';
\r
83 $mime['nc'] = 'application/x-netcdf';
\r
84 $mime['cdf'] = 'application/x-netcdf';
\r
85 $mime['rpm'] = 'application/x-rpm';
\r
86 $mime['sh'] = 'application/x-sh';
\r
87 $mime['shar'] = 'application/x-shar';
\r
88 $mime['swf'] = 'application/x-shockwave-flash';
\r
89 $mime['sit'] = 'application/x-stuffit';
\r
90 $mime['sv4cpio'] = 'application/x-sv4cpio';
\r
91 $mime['sv4crc'] = 'application/x-sv4crc';
\r
92 $mime['tar'] = 'application/x-tar';
\r
93 $mime['tcl'] = 'application/x-tcl';
\r
94 $mime['tex'] = 'application/x-tex';
\r
95 $mime['texinfo'] = 'application/x-texinfo';
\r
96 $mime['texi'] = 'application/x-texinfo';
\r
97 $mime['t'] = 'application/x-troff';
\r
98 $mime['tr'] = 'application/x-troff';
\r
99 $mime['roff'] = 'application/x-troff';
\r
100 $mime['man'] = 'application/x-troff-man';
\r
101 $mime['me'] = 'application/x-troff-me';
\r
102 $mime['ms'] = 'application/x-troff-ms';
\r
103 $mime['ustar'] = 'application/x-ustar';
\r
104 $mime['src'] = 'application/x-wais-source';
\r
105 $mime['zip'] = 'application/zip';
\r
106 $mime['au'] = 'audio/basic';
\r
107 $mime['snd'] = 'audio/basic';
\r
108 $mime['mid'] = 'audio/midi';
\r
109 $mime['midi'] = 'audio/midi';
\r
110 $mime['kar'] = 'audio/midi';
\r
111 $mime['mpga'] = 'audio/mpeg';
\r
112 $mime['mp2'] = 'audio/mpeg';
\r
113 $mime['mp3'] = 'audio/mpeg';
\r
114 $mime['aif'] = 'audio/x-aiff';
\r
115 $mime['aiff'] = 'audio/x-aiff';
\r
116 $mime['aifc'] = 'audio/x-aiff';
\r
117 $mime['ram'] = 'audio/x-pn-realaudio';
\r
118 $mime['rm'] = 'audio/x-pn-realaudio';
\r
119 $mime['ra'] = 'audio/x-realaudio';
\r
120 $mime['wav'] = 'audio/x-wav';
\r
121 $mime['pdb'] = 'chemical/x-pdb';
\r
122 $mime['xyz'] = 'chemical/x-pdb';
\r
123 $mime['gif'] = 'image/gif';
\r
124 $mime['ief'] = 'image/ief';
\r
125 $mime['jpeg'] = 'image/jpeg';
\r
126 $mime['jpg'] = 'image/jpeg';
\r
127 $mime['jpe'] = 'image/jpeg';
\r
128 $mime['png'] = 'image/png';
\r
129 $mime['tiff'] = 'image/tiff';
\r
130 $mime['tif'] = 'image/tiff';
\r
131 $mime['wbmp'] = 'image/vnd.wap.wbmp';
\r
132 $mime['ras'] = 'image/x-cmu-raster';
\r
133 $mime['pnm'] = 'image/x-portable-anymap';
\r
134 $mime['pbm'] = 'image/x-portable-bitmap';
\r
135 $mime['pgm'] = 'image/x-portable-graymap';
\r
136 $mime['ppm'] = 'image/x-portable-pixmap';
\r
137 $mime['rgb'] = 'image/x-rgb';
\r
138 $mime['xbm'] = 'image/x-xbitmap';
\r
139 $mime['xpm'] = 'image/x-xpixmap';
\r
140 $mime['xwd'] = 'image/x-xwindowdump';
\r
141 $mime['igs'] = 'model/iges';
\r
142 $mime['iges'] = 'model/iges';
\r
143 $mime['msh'] = 'model/mesh';
\r
144 $mime['mesh'] = 'model/mesh';
\r
145 $mime['silo'] = 'model/mesh';
\r
146 $mime['wrl'] = 'model/vrml';
\r
147 $mime['vrml'] = 'model/vrml';
\r
148 $mime['css'] = 'text/css';
\r
149 $mime['asc'] = 'text/plain';
\r
150 $mime['txt'] = 'text/plain';
\r
151 $mime['rtx'] = 'text/richtext';
\r
152 $mime['rtf'] = 'text/rtf';
\r
153 $mime['sgml'] = 'text/sgml';
\r
154 $mime['sgm'] = 'text/sgml';
\r
155 $mime['tsv'] = 'text/tab-separated-values';
\r
156 $mime['sl'] = 'text/vnd.wap.sl';
\r
157 $mime['si'] = 'text/vnd.wap.si';
\r
158 $mime['wml'] = 'text/vnd.wap.wml';
\r
159 $mime['wmls'] = 'text/vnd.wap.wmlscript';
\r
160 $mime['etx'] = 'text/x-setext';
\r
161 $mime['xml'] = 'text/xml';
\r
162 $mime['mpeg'] = 'video/mpeg';
\r
163 $mime['mpg'] = 'video/mpeg';
\r
164 $mime['mpe'] = 'video/mpeg';
\r
165 $mime['qt'] = 'video/quicktime';
\r
166 $mime['mov'] = 'video/quicktime';
\r
167 $mime['avi'] = 'video/x-msvideo';
\r
168 $mime['movie'] = 'video/x-sgi-movie';
\r
169 $mime['ice'] = 'x-conference/x-cooltalk';
\r
170 $mime['html'] = 'text/html';
\r
171 $mime['htm'] = 'text/html';
\r
172 $mime['xls'] = 'application/vnd.ms-excel';
\r
173 $mime['log'] = 'text/plain';
\r
175 $force_download = false;
\r
178 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
\r
179 if (!empty($_SERVER['PATH_INFO'])) {
\r
180 $current_file = $_SERVER['PATH_INFO'];
\r
181 } else if (!empty($_SERVER['REQUEST_URI'])) {
\r
182 $current_file = $_SERVER['REQUEST_URI'];
\r
183 } else if (!empty($_SERVER['PHP_SELF'])) {
\r
184 if (!empty($_SERVER['QUERY_STRING'])) {
\r
185 $current_file = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
\r
187 $current_file = $_SERVER['PHP_SELF'];
\r
189 } else if (!empty($_SERVER['SCRIPT_NAME'])) {
\r
190 if (!empty($_SERVER['QUERY_STRING'])) {
\r
191 $current_file = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
\r
193 $current_file = $_SERVER['SCRIPT_NAME'];
\r
195 } else if (!empty($_SERVER['URL'])) {
\r
196 if (!empty($_SERVER['QUERY_STRING'])) {
\r
197 $current_file = $_SERVER['URL'] . '?' . $_SERVER['QUERY_STRING'];
\r
199 $current_file = $_SERVER['URL'];
\r
202 if (($pos = strpos($current_file, '/get_pa.php/')) !== FALSE) {
\r
203 $current_file = substr($current_file, $pos + strlen('/get_pa.php/'));
\r
206 if (substr($current_file, 0, 2) == '/@') {
\r
207 $force_download = true;
\r
208 $current_file = substr($current_file, 2);
\r
212 $current_file = $_GET['f'];
\r
214 if (substr($current_file, 0, 2) == '/@') {
\r
215 $force_download = true;
\r
216 $current_file = substr($current_file, 2);
\r
220 $file_name = pathinfo($current_file);
\r
221 $file_name = $file_name['basename'];
\r
223 $file = AT_CONTENT_DIR . $current_file;
\r
225 //send header mime type
\r
226 $ext = pathinfo($file);
\r
227 $ext = $ext['extension'];
\r
229 $ext = 'application/octet-stream';
\r
231 $ext = $mime[$ext];
\r
234 //check that this file is within the content directory & exists
\r
236 // NOTE!! for some reason realpath() is not returning FALSE when the file doesn't exist! NOTE!!
\r
237 $real = realpath($file);
\r
239 if (file_exists($real) && (substr($real, 0, strlen(AT_CONTENT_DIR)) == AT_CONTENT_DIR)) {
\r
240 if ($force_download) {
\r
241 header('Content-Type: application/force-download');
\r
242 header('Content-transfer-encoding: binary');
\r
243 header('Content-Disposition: attachment; filename="'.$file_name.'"');
\r
246 header('Content-Type: '.$ext);
\r
248 echo @file_get_contents($real);
\r
251 header('HTTP/1.1 404 Not Found', TRUE);
\r