104 |
- |
1 |
<?php
|
|
|
2 |
include_once ($_SERVER['DOCUMENT_ROOT'] . "/php/dnsexit.php");
|
|
|
3 |
|
|
|
4 |
//set array of allowed file types to prevent abuse
|
|
|
5 |
$allowed = array('css','js','png','jpg','jpeg','gif','svg','ico');
|
|
|
6 |
|
|
|
7 |
//check for request variable existence and that file type is allowed
|
106 |
- |
8 |
if(isset($_GET['file']) && isset($_GET['type']) && in_array(substr($_GET['file'],strrpos($_GET['file'],'.')+1), $allowed)) {
|
|
|
9 |
if (!$data = @file_get_contents(dirname(__FILE__).'/'.$_GET['file'])) { // grab the file contents
|
|
|
10 |
exit;
|
107 |
- |
11 |
}
|
104 |
- |
12 |
|
|
|
13 |
$etag = '"'.md5($data).'"'; // generate a file Etag
|
|
|
14 |
header('ETag: '.$etag); // output the Etag in the header
|
|
|
15 |
|
|
|
16 |
// output the content-type header for each file type
|
|
|
17 |
switch ($_GET['type']) {
|
|
|
18 |
case 'css':
|
|
|
19 |
header ("Content-Type: text/css; charset: UTF-8");
|
|
|
20 |
break;
|
|
|
21 |
|
|
|
22 |
case 'js':
|
|
|
23 |
header ("Content-Type: text/javascript; charset: UTF-8");
|
|
|
24 |
break;
|
|
|
25 |
|
|
|
26 |
case 'png':
|
|
|
27 |
header ("Content-Type: image/png");
|
|
|
28 |
break;
|
|
|
29 |
|
|
|
30 |
case 'jpg':
|
|
|
31 |
case 'jpeg':
|
|
|
32 |
header ("Content-Type: image/jpeg");
|
|
|
33 |
break;
|
|
|
34 |
|
|
|
35 |
case 'gif':
|
|
|
36 |
header ("Content-Type: image/gif");
|
|
|
37 |
break;
|
|
|
38 |
|
|
|
39 |
case 'svg':
|
|
|
40 |
header ("Content-Type: image/svg+xml");
|
|
|
41 |
break;
|
|
|
42 |
|
|
|
43 |
case 'ico':
|
|
|
44 |
header ("Content-Type: image/vnd.microsoft.icon");
|
|
|
45 |
break;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
header('Cache-Control: max-age=86400, public'); //output the cache-control header
|
|
|
49 |
|
|
|
50 |
// check the Etag the browser already has for the file and only serve the file if it is different
|
|
|
51 |
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $etag == $_SERVER['HTTP_IF_NONE_MATCH']) {
|
|
|
52 |
header('HTTP/1.1 304 Not Modified');
|
|
|
53 |
header('Content-Length: 0');
|
|
|
54 |
} else {
|
|
|
55 |
echo $data;
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
?>
|