thumbnail.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Elgg file thumbnail
  4. *
  5. * @package ElggFile
  6. */
  7. // Get engine
  8. require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
  9. // Get file GUID
  10. $file_guid = (int) get_input('file_guid', 0);
  11. // Get file thumbnail size
  12. $size = get_input('size', 'small');
  13. $file = get_entity($file_guid);
  14. if (!elgg_instanceof($file, 'object', 'file')) {
  15. exit;
  16. }
  17. $simpletype = $file->simpletype;
  18. if ($simpletype == "image") {
  19. // Get file thumbnail
  20. switch ($size) {
  21. case "small":
  22. $thumbfile = $file->thumbnail;
  23. break;
  24. case "medium":
  25. $thumbfile = $file->smallthumb;
  26. break;
  27. case "large":
  28. default:
  29. $thumbfile = $file->largethumb;
  30. break;
  31. }
  32. // Grab the file
  33. if ($thumbfile && !empty($thumbfile)) {
  34. $readfile = new ElggFile();
  35. $readfile->owner_guid = $file->owner_guid;
  36. $readfile->setFilename($thumbfile);
  37. $mime = $file->getMimeType();
  38. $contents = $readfile->grabFile();
  39. // caching images for 10 days
  40. header("Content-type: $mime");
  41. header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
  42. header("Pragma: public", true);
  43. header("Cache-Control: public", true);
  44. header("Content-Length: " . strlen($contents));
  45. echo $contents;
  46. exit;
  47. }
  48. }