3 if (!defined('GNUSOCIAL')) { exit(1); }
6 * View notice attachment
9 * @author Miguel Dantas <biodantasgs@gmail.com>
10 * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
12 class Attachment_viewAction extends AttachmentAction
14 public function showPage()
16 // Checks file exists or throws FileNotFoundException
17 $filepath = $this->attachment->getFileOrThumbnailPath();
18 $filesize = $this->attachment->getFileOrThumbnailSize();
19 $mimetype = $this->attachment->getFileOrThumbnailMimetype();
21 if (empty($filepath)) {
22 $this->clientError(_('No such attachment'), 404);
25 $filename = MediaFile::getDisplayName($this->attachment);
27 // Disable errors, to not mess with the file contents (suppress errors in case access to this
28 // function is blocked, like in some shared hosts). Automatically reset at the end of the
29 // script execution, and we don't want to have any more errors until then, so don't reset it
30 @ini_set('display_errors', 0);
32 header("Content-Description: File Transfer");
33 header("Content-Type: {$mimetype}");
34 if (in_array(common_get_mime_media($mimetype), ['image', 'video'])) {
35 header("Content-Disposition: inline; filename=\"{$filename}\"");
37 header("Content-Disposition: attachment; filename=\"{$filename}\"");
40 header('Content-Transfer-Encoding: binary');
42 AttachmentAction::sendFile($filepath, $filesize);