3 if (!defined('GNUSOCIAL')) { exit(1); }
6 * Download notice attachment
10 * @author Mikael Nordfeldth <mmn@hethane.se>
11 * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
12 * @link https:/gnu.io/social
14 class Attachment_downloadAction extends AttachmentAction
16 public function showPage()
18 // Checks file exists or throws FileNotFoundException
19 $filepath = $this->attachment->getFileOrThumbnailPath();
20 $filesize = $this->attachment->getFileOrThumbnailSize();
21 $mimetype = $this->attachment->getFileOrThumbnailMimetype();
23 if (empty($filepath)) {
24 $thiis->clientError(_('No such attachment'), 404);
27 $filename = MediaFile::getDisplayName($this->attachment);
29 // Disable errors, to not mess with the file contents (suppress errors in case access to this
30 // function is blocked, like in some shared hosts). Automatically reset at the end of the
31 // script execution, and we don't want to have any more errors until then, so don't reset it
32 @ini_set('display_errors', 0);
34 header("Content-Description: File Transfer");
35 header("Content-Type: {$mimetype}");
36 header("Content-Disposition: attachment; filename=\"{$filename}\"");
38 header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
40 AttachmentAction::sendFile($filepath, $filesize);