Rev 107 | Blame | Last modification | View Log | RSS feed
<?php
include_once ($_SERVER['DOCUMENT_ROOT'] . "/php/hosting.php");
//set array of allowed file types to prevent abuse
$allowed = array('css','js','png','jpg','jpeg','gif','svg','ico');
//check for request variable existence and that file type is allowed
if(isset($_GET['file']) && isset($_GET['type']) && in_array(substr($_GET['file'],strrpos($_GET['file'],'.')+1), $allowed)) {
if (!$data = @file_get_contents(dirname(__FILE__).'/'.$_GET['file'])) { // grab the file contents
exit;
}
$etag = '"'.md5($data).'"'; // generate a file Etag
header('ETag: '.$etag); // output the Etag in the header
// output the content-type header for each file type
switch ($_GET['type']) {
case 'css':
header ("Content-Type: text/css; charset: UTF-8");
break;
case 'js':
header ("Content-Type: text/javascript; charset: UTF-8");
break;
case 'png':
header ("Content-Type: image/png");
break;
case 'jpg':
case 'jpeg':
header ("Content-Type: image/jpeg");
break;
case 'gif':
header ("Content-Type: image/gif");
break;
case 'svg':
header ("Content-Type: image/svg+xml");
break;
case 'ico':
header ("Content-Type: image/vnd.microsoft.icon");
break;
}
header('Cache-Control: max-age=86400, public'); //output the cache-control header
// check the Etag the browser already has for the file and only serve the file if it is different
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $etag == $_SERVER['HTTP_IF_NONE_MATCH']) {
header('HTTP/1.1 304 Not Modified');
header('Content-Length: 0');
} else {
echo $data;
}
}
?>