attachment_download.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. if (!defined('GNUSOCIAL')) { exit(1); }
  3. /**
  4. * Download notice attachment
  5. *
  6. * @category Personal
  7. * @package GNUsocial
  8. * @author Mikael Nordfeldth <mmn@hethane.se>
  9. * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  10. * @link https:/gnu.io/social
  11. */
  12. class Attachment_downloadAction extends AttachmentAction
  13. {
  14. public function showPage()
  15. {
  16. // Checks file exists or throws FileNotStoredLocallyException
  17. $filepath = $this->attachment->getPath();
  18. $filename = MediaFile::getDisplayName($this->attachment);
  19. // Disable errors, to not mess with the file contents (suppress errors in case access to this
  20. // function is blocked, like in some shared hosts). Automatically reset at the end of the
  21. // script execution, and we don't want to have any more errors until then, so don't reset it
  22. @ini_set('display_errors', 0);
  23. header("Content-Description: File Transfer");
  24. header("Content-Type: {$this->attachment->mimetype}");
  25. header("Content-Disposition: attachment; filename=\"{$filename}\"");
  26. header('Expires: 0');
  27. header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
  28. $this->sendFile($filepath);
  29. }
  30. }