blob: 1f35afa3a72e8e527ed901ec55cd910f4046b2e2 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01003if (!isset($_GET['file']) ) {
4 http_response_code(404);
5 exit;
6}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01007$pathinfo = pathinfo($_GET['file']);
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01008
9if (!array_key_exists('extension', $pathinfo)) {
10 http_response_code(404);
11 exit;
12}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010013$extension = strtolower($pathinfo['extension']);
14
15$filepath = '/tmp/' . $pathinfo['basename'];
16$content = '';
17
18if (file_exists($filepath)) {
19 $secondsToCache = 31536000;
20 $expires = gmdate('D, d M Y H:i:s', time() + $secondsToCache) . ' GMT';
21
22 if ($extension === 'js') {
23 header('Content-Type: application/javascript');
24 } elseif ($extension === 'css') {
25 header('Content-Type: text/css');
26 } else {
27 //currently just css and js should be supported!
28 exit();
29 }
30
31 header("Expires: $expires");
32 header('Pragma: cache');
33 header('Cache-Control: max-age=' . $secondsToCache);
34 $content = file_get_contents($filepath);
35}
36
37echo $content;