resource.php 898 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. if (!isset($_GET['file']) ) {
  3. http_response_code(404);
  4. exit;
  5. }
  6. $pathinfo = pathinfo($_GET['file']);
  7. if (!array_key_exists('extension', $pathinfo)) {
  8. http_response_code(404);
  9. exit;
  10. }
  11. $extension = strtolower($pathinfo['extension']);
  12. $filepath = '/tmp/' . $pathinfo['basename'];
  13. $content = '';
  14. if (file_exists($filepath)) {
  15. $secondsToCache = 31536000;
  16. $expires = gmdate('D, d M Y H:i:s', time() + $secondsToCache) . ' GMT';
  17. if ($extension === 'js') {
  18. header('Content-Type: application/javascript');
  19. } elseif ($extension === 'css') {
  20. header('Content-Type: text/css');
  21. } else {
  22. //currently just css and js should be supported!
  23. exit();
  24. }
  25. header("Expires: $expires");
  26. header('Pragma: cache');
  27. header('Cache-Control: max-age=' . $secondsToCache);
  28. $content = file_get_contents($filepath);
  29. }
  30. echo $content;