image.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
  3. get_include_path());
  4. require_once "config.php";
  5. // backwards compatible wrapper for old-style image caching
  6. /* if (isset($_GET['url'])) {
  7. $url = base64_decode($_GET['url']);
  8. $filename = CACHE_DIR . '/images/' . sha1($url) . '.png';
  9. if (file_exists($filename)) {
  10. header("Content-type: image/png");
  11. echo file_get_contents($filename);
  12. } else {
  13. header("Location: $url");
  14. }
  15. return;
  16. } */
  17. @$hash = basename($_GET['hash']);
  18. if ($hash) {
  19. $filename = CACHE_DIR . '/images/' . $hash . '.png';
  20. if (file_exists($filename)) {
  21. /* See if we can use X-Sendfile */
  22. $xsendfile = false;
  23. if (function_exists('apache_get_modules') &&
  24. array_search('mod_xsendfile', apache_get_modules()))
  25. $xsendfile = true;
  26. if ($xsendfile) {
  27. header("X-Sendfile: $filename");
  28. header("Content-type: application/octet-stream");
  29. header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
  30. } else {
  31. header("Content-type: image/png");
  32. $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT";
  33. header("Last-Modified: $stamp", true);
  34. readfile($filename);
  35. }
  36. } else {
  37. header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
  38. echo "File not found.";
  39. }
  40. }
  41. ?>