|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
******************************************************************************* |
|
4
|
|
|
* Copyright 2011-2017 DANTE Ltd. and GÉANT on behalf of the GN3, GN3+, GN4-1 |
|
5
|
|
|
* and GN4-2 consortia |
|
6
|
|
|
* |
|
7
|
|
|
* License: see the web/copyright.php file in the file structure |
|
8
|
|
|
******************************************************************************* |
|
9
|
|
|
*/ |
|
10
|
|
|
?> |
|
11
|
|
|
<?php |
|
12
|
|
|
|
|
13
|
|
|
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/config/_config.php"); |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* retrieves a binary object from the database and pushes it out to the browser |
|
17
|
|
|
* @param string $id |
|
18
|
|
|
* @return void in case of error - otherwise, sends the content directly to browser and never returns |
|
19
|
|
|
*/ |
|
20
|
|
|
function getObjectFromDB($id) { |
|
21
|
|
|
|
|
22
|
|
|
// check if data is public for this blob call |
|
23
|
|
|
|
|
24
|
|
|
$blob = \web\lib\admin\UIElements::getBlobFromDB($id, TRUE); |
|
25
|
|
|
$finalBlob = base64_decode($blob); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
if ($finalBlob === FALSE) { |
|
28
|
|
|
return; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
// Set data type and caching for 30 days |
|
32
|
|
|
$info = new finfo(); |
|
33
|
|
|
$filetype = $info->buffer($finalBlob, FILEINFO_MIME_TYPE); |
|
34
|
|
|
header("Content-type: " . $filetype); |
|
35
|
|
|
|
|
36
|
|
|
switch ($filetype) { |
|
37
|
|
|
case "text/rtf": // fall-through, same treatment |
|
38
|
|
|
case "application/rtf": |
|
39
|
|
|
header("Content-Disposition: attachment; filename='download.rtf'"); |
|
40
|
|
|
break; |
|
41
|
|
|
case "text/plain": |
|
42
|
|
|
header("Content-Disposition: attachment; filename='download.txt'"); |
|
43
|
|
|
break; |
|
44
|
|
|
default: |
|
45
|
|
|
// do nothing special with the Content-Disposition header |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
header("Cache-Control: must-revalidate"); |
|
49
|
|
|
$offset = 60 * 60 * 24 * 30; |
|
50
|
|
|
// gmdate can't possibly fail, because it operates on time() and an integer offset |
|
51
|
|
|
|
|
52
|
|
|
$ExpStr = "Expires: " . /** @scrutinizer ignore-type */ gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; |
|
53
|
|
|
header($ExpStr); |
|
54
|
|
|
|
|
55
|
|
|
// Print out the image |
|
56
|
|
|
echo $finalBlob; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$validator = new \web\lib\common\InputValidation(); |
|
60
|
|
|
if (isset($_GET["id"]) && $validator->databaseReference($_GET["id"])) { |
|
61
|
|
|
getObjectFromDB($_GET["id"]); |
|
62
|
|
|
} else { |
|
63
|
|
|
echo "No valid ID"; |
|
64
|
|
|
} |
|
65
|
|
|
|