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
|
<?php
$allowedExtensions = array(
// archives
'zip' => 'application/zip',
'tgz' => 'application/tar',
// documents
'pdf' => 'application/pdf',
'doc' => 'application/msword',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'csv' => 'application/vnd.ms-excel',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
// executables
'exe' => 'application/octet-stream',
// text
'xml' => 'text/xml',
// images
'gif' => 'image/gif',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
// audio
'mp3' => 'audio/mpeg',
'wav' => 'audio/x-wav',
// video
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'mov' => 'video/quicktime',
'avi' => 'video/x-msvideo'
);
$allowedMimeTypes = array(
'application/zip',
'application/tar',
'application/pdf',
'application/msword',
'application/vnd.ms-excel',
'application/vnd.ms-powerpoint',
'application/octet-stream',
'text/xml',
'image/gif',
'image/png',
'image/jpeg',
'audio/mpeg',
'audio/x-wav',
'video/mpeg',
'video/quicktime',
'video/x-msvideo',
'application/vnd.oasis.opendocument.spreadsheet'
);
function passFile($ADAT) {
if (in_array($ADAT['ext'],array('jpg','jpeg','png'))) passFile_image($ADAT);
else passFile_other($ADAT);
die();
}
function passFile_image($ADAT) {
ob_clean();
ignore_user_abort(true);
set_time_limit(0);
// Getting headers sent by the client.
$headers = apache_request_headers();
$fn = $ADAT['path'] ;
// Checking if the client is validating his cache and if it is current.
if (isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == filemtime($fn))) {
// Client's cache IS current, so we just respond '304 Not Modified'.
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($fn)).' GMT', true, 304);
header('Expires: '.gmdate('D, d M Y H:i:s', strtotime('+10 day')).' GMT', true);
header("Cache-Control: max-age=604800, public", true);
header("Pragma: public", true);
} else {
header("Pragma: public", true);
header("Cache-Control: max-age=604800, public", true);
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($fn)).' GMT', true, 200);
header('Expires: '.gmdate('D, d M Y H:i:s', strtotime('+10 day')).' GMT', true);
header("Content-Length: " . $ADAT['size'], true);
header('Content-type: '.$ADAT['mime'], true);
echo file_get_contents($fn);
}
}
function passFile_other($ADAT) {
ob_clean();
header('Content-type: '.$ADAT['mime']);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: ".$ADAT['mime']);
if (!isset($ADAT['pure'])) // akkor force download as
header('Content-Disposition: attachment; filename="'.$ADAT['file'].'"');
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $ADAT['size']);
echo file_get_contents($ADAT['path']);
}
?>
|