Rev 106 | Blame | Last modification | View Log | RSS feed
<?phpinclude_once ($_SERVER['DOCUMENT_ROOT'] . "/php/dnsexit.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 allowedif(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 contentsexit;}$etag = '"'.md5($data).'"'; // generate a file Etagheader('ETag: '.$etag); // output the Etag in the header// output the content-type header for each file typeswitch ($_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 differentif (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;}}?>