]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/attachment_view.php
Added type-hint for StartShowEntryForms hook
[quix0rs-gnu-social.git] / actions / attachment_view.php
1 <?php
2
3 if (!defined('GNUSOCIAL')) { exit(1); }
4
5 /**
6  * View notice attachment
7  *
8  * @package  GNUsocial
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
11  */
12 class Attachment_viewAction extends AttachmentAction
13 {
14     public function showPage()
15     {
16         // Checks file exists or throws FileNotFoundException
17         $filepath = $this->attachment->getFileOrThumbnailPath();
18         $filesize = $this->attachment->getFileOrThumbnailSize();
19         $mimetype = $this->attachment->getFileOrThumbnailMimetype();
20
21         if (empty($filepath)) {
22             $this->clientError(_('No such attachment'), 404);
23         }
24
25         $filename = MediaFile::getDisplayName($this->attachment);
26
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);
31
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}\"");
36         } else {
37             header("Content-Disposition: attachment; filename=\"{$filename}\"");
38         }
39         header('Expires: 0');
40         header('Content-Transfer-Encoding: binary');
41
42         AttachmentAction::sendFile($filepath, $filesize);
43     }
44 }