download.php 967 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Download a photo
  4. *
  5. * @author Cash Costello
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
  7. */
  8. $guid = (int) get_input('guid');
  9. $image = get_entity($guid);
  10. $disposition = get_input('disposition', 'attachment');
  11. if ($image) {
  12. $filename = $image->originalfilename;
  13. $mime = $image->mimetype;
  14. header("Content-Type: $mime");
  15. header("Content-Disposition: $disposition; filename=\"$filename\"");
  16. $contents = $image->grabFile();
  17. if (empty($contents)) {
  18. echo file_get_contents(dirname(dirname(__FILE__)) . "/graphics/image_error_large.png" );
  19. } else {
  20. // expires every 60 days
  21. $expires = 60 * 60*60*24;
  22. header("Content-Length: " . strlen($contents));
  23. header("Cache-Control: public", true);
  24. header("Pragma: public", true);
  25. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT', true);
  26. echo $contents;
  27. }
  28. exit;
  29. } else {
  30. register_error(elgg_echo("image:downloadfailed"));
  31. }