-
Notifications
You must be signed in to change notification settings - Fork 35
/
get.php
135 lines (117 loc) · 4.54 KB
/
get.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/************************************************************************/
/* AContent */
/************************************************************************/
/* Copyright (c) 2010 */
/* Inclusive Design Institute */
/* */
/* This program is free software. You can redistribute it and/or */
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation. */
/************************************************************************/
define('TR_INCLUDE_PATH', 'include/');
@ob_end_clean();
header("Content-Encoding: none");
if (isset($_GET['test'])) {
header('HTTP/1.1 200 OK', TRUE);
header('Trans-Get: OK');
exit;
}
$in_get = TRUE;
require(TR_INCLUDE_PATH . 'vitals.inc.php');
require(TR_INCLUDE_PATH . 'lib/mime.inc.php');
$force_download = false;
//get path to file
if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
if ((version_compare(phpversion(), '5.2.0', '<') > 0) && !empty($_SERVER['ORIG_PATH_INFO'])){
//http://www.atutor.ca/atutor/mantis/view.php?id=3436
$current_file = $_SERVER['ORIG_PATH_INFO'];
} else if (!empty($_SERVER['PATH_INFO'])) {
$current_file = $_SERVER['PATH_INFO'];
} else if (!empty($_SERVER['REQUEST_URI'])) {
$current_file = $_SERVER['REQUEST_URI'];
} else if (!empty($_SERVER['PHP_SELF'])) {
if (!empty($_SERVER['QUERY_STRING'])) {
$current_file = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
} else {
$current_file = $_SERVER['PHP_SELF'];
}
} else if (!empty($_SERVER['SCRIPT_NAME'])) {
if (!empty($_SERVER['QUERY_STRING'])) {
$current_file = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
} else {
$current_file = $_SERVER['SCRIPT_NAME'];
}
} else if (!empty($_SERVER['URL'])) {
if (!empty($_SERVER['QUERY_STRING'])) {
$current_file = $_SERVER['URL'] . '?' . $_SERVER['QUERY_STRING'];
}
$current_file = $_SERVER['URL'];
}
if (($pos = strpos($current_file, '/get.php')) !== FALSE) {
$current_file = substr($current_file, $pos + strlen('/get.php'));
}
if (substr($current_file, 0, 2) == '/@') {
$force_download = true;
$current_file = substr($current_file, 2);
}
} else {
$current_file = $_GET['f'];
if (substr($current_file, 0, 2) == '/@') {
$force_download = true;
$current_file = substr($current_file, 2);
}
}
$file_name = pathinfo($current_file);
$file_name = $file_name['basename'];
if (substr($file_name, 0, 4) == 'b64:') {
$base64_file_name = substr($file_name, 4);
$file_name = base64_decode($base64_file_name);
$current_file = '/'.$file_name;
}
$file = TR_CONTENT_DIR . $_SESSION['course_id'] . $current_file;
//send header mime type
$pathinfo = pathinfo($file);
$ext = $pathinfo['extension'];
if ($ext == '') {
$ext = 'application/octet-stream';
} else {
$ext = $mime[$ext][0];
}
//check that this file is within the content directory & exists
// NOTE!! for some reason realpath() is not returning FALSE when the file doesn't exist!
$real = realpath($file);
if (file_exists($real) && (substr($real, 0, strlen(TR_CONTENT_DIR)) == TR_CONTENT_DIR)) {
if ($force_download) {
header('Content-Type: application/force-download');
header('Content-transfer-encoding: binary');
header('Content-Disposition: attachment; filename="'.$pathinfo['basename'].'"');
} else {
header('Content-Disposition: filename="'.$pathinfo['basename'].'"');
}
/**
* although we can check if mod_xsendfile is installed in apache2
* we can't actually check if it's enabled. also, we can't check if
* it's enabled and installed in lighty, so instead we send the
* header anyway, if it works then the line after it will not
* execute. if it doesn't work, then the line after it will replace
* it so that the full server path is not exposed.
*
* x-sendfile is supported in apache2 and lighttpd 1.5+ (previously
* named x-send-file in lighttpd 1.4)
*/
header('x-Sendfile: '.$real);
header('x-Sendfile: ', TRUE); // if we get here then it didn't work
header('Content-Type: '.$ext);
//a hack for http://atutor.ca/atutor/mantis/view.php?id=4531
//@harris
if ($pathinfo['extension']=='mp3' || $pathinfo['extension']=='mp4') {
header('Content-length: '.filesize($real));
}
@readfile($real);
exit;
} else {
header('HTTP/1.1 404 Not Found', TRUE);
exit;
}
?>