Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | <?php |
| 2 | |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 3 | if (!isset($_GET['file']) ) { |
| 4 | http_response_code(404); |
| 5 | exit; |
| 6 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 7 | $pathinfo = pathinfo($_GET['file']); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 8 | |
| 9 | if (!array_key_exists('extension', $pathinfo)) { |
| 10 | http_response_code(404); |
| 11 | exit; |
| 12 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 13 | $extension = strtolower($pathinfo['extension']); |
| 14 | |
| 15 | $filepath = '/tmp/' . $pathinfo['basename']; |
| 16 | $content = ''; |
| 17 | |
| 18 | if (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 | |
| 37 | echo $content; |