2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
13 define('AT_INCLUDE_PATH', 'include/');
15 header("Content-Encoding: none");
16 if (isset($_GET['test'])) {
17 header('HTTP/1.1 200 OK', TRUE);
18 header('ATutor-Get: OK');
23 require(AT_INCLUDE_PATH . 'vitals.inc.php');
24 require(AT_INCLUDE_PATH . 'lib/mime.inc.php');
26 $force_download = false;
29 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
30 if ((version_compare(phpversion(), '5.2.0', '<') > 0) && !empty($_SERVER['ORIG_PATH_INFO'])){
31 //http://www.atutor.ca/atutor/mantis/view.php?id=3436
32 $current_file = $_SERVER['ORIG_PATH_INFO'];
33 } else if (!empty($_SERVER['PATH_INFO'])) {
34 $current_file = $_SERVER['PATH_INFO'];
35 } else if (!empty($_SERVER['REQUEST_URI'])) {
36 $current_file = $_SERVER['REQUEST_URI'];
37 } else if (!empty($_SERVER['PHP_SELF'])) {
38 if (!empty($_SERVER['QUERY_STRING'])) {
39 $current_file = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
41 $current_file = $_SERVER['PHP_SELF'];
43 } else if (!empty($_SERVER['SCRIPT_NAME'])) {
44 if (!empty($_SERVER['QUERY_STRING'])) {
45 $current_file = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
47 $current_file = $_SERVER['SCRIPT_NAME'];
49 } else if (!empty($_SERVER['URL'])) {
50 if (!empty($_SERVER['QUERY_STRING'])) {
51 $current_file = $_SERVER['URL'] . '?' . $_SERVER['QUERY_STRING'];
53 $current_file = $_SERVER['URL'];
56 if (($pos = strpos($current_file, '/get.php')) !== FALSE) {
57 $current_file = substr($current_file, $pos + strlen('/get.php'));
59 if (substr($current_file, 0, 2) == '/@') {
60 $force_download = true;
61 $current_file = substr($current_file, 2);
65 $current_file = $_GET['f'];
67 if (substr($current_file, 0, 2) == '/@') {
68 $force_download = true;
69 $current_file = substr($current_file, 2);
73 $file_name = pathinfo($current_file);
74 $file_name = $file_name['basename'];
76 if (substr($file_name, 0, 4) == 'b64:') {
77 $base64_file_name = substr($file_name, 4);
78 $file_name = base64_decode($base64_file_name);
79 $current_file = '/'.$file_name;
83 $file = AT_CONTENT_DIR . $_SESSION['course_id'] . $current_file;
85 //send header mime type
86 $pathinfo = pathinfo($file);
88 $ext = $pathinfo['extension'];
90 $ext = 'application/octet-stream';
92 $ext = $mime[$ext][0];
95 //check that this file is within the content directory & exists
97 // NOTE!! for some reason realpath() is not returning FALSE when the file doesn't exist!
98 $real = realpath($file);
99 if (file_exists($real) && (substr($real, 0, strlen(AT_CONTENT_DIR)) == AT_CONTENT_DIR)) {
100 if ($force_download) {
101 header('Content-Type: application/force-download');
102 header('Content-transfer-encoding: binary');
103 header('Content-Disposition: attachment; filename="'.$pathinfo['basename'].'"');
105 header('Content-Disposition: filename="'.$pathinfo['basename'].'"');
109 * although we can check if mod_xsendfile is installed in apache2
110 * we can't actually check if it's enabled. also, we can't check if
111 * it's enabled and installed in lighty, so instead we send the
112 * header anyway, if it works then the line after it will not
113 * execute. if it doesn't work, then the line after it will replace
114 * it so that the full server path is not exposed.
116 * x-sendfile is supported in apache2 and lighttpd 1.5+ (previously
117 * named x-send-file in lighttpd 1.4)
119 header('x-Sendfile: '.$real);
120 header('x-Sendfile: ', TRUE); // if we get here then it didn't work
122 header('Content-Type: '.$ext);
123 //a hack for http://atutor.ca/atutor/mantis/view.php?id=4531
125 if ($pathinfo['extension']=='mp3' || $pathinfo['extension']=='mp4') {
126 header('Content-length: '.filesize($real));
132 header('HTTP/1.1 404 Not Found', TRUE);