]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/attachment_download.php
[CORE][StoreRemoteMedia] Fixed bug where sometimes images were written outside the...
[quix0rs-gnu-social.git] / actions / attachment_download.php
1 <?php
2
3 if (!defined('GNUSOCIAL')) { exit(1); }
4
5 /**
6  * Download notice attachment
7  *
8  * @category Personal
9  * @package  GNUsocial
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
13  */
14 class Attachment_downloadAction extends AttachmentAction
15 {
16     public function showPage()
17     {
18         // Checks file exists or throws FileNotFoundException
19         $filepath = $this->attachment->getFileOrThumbnailPath();
20         $filesize = $this->attachment->getFileOrThumbnailSize();
21         $mimetype = $this->attachment->getFileOrThumbnailMimetype();
22
23         if (empty($filepath)) {
24             $thiis->clientError(_('No such attachment'), 404);
25         }
26
27         $filename = MediaFile::getDisplayName($this->attachment);
28
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);
33
34         header("Content-Description: File Transfer");
35         header("Content-Type: {$mimetype}");
36         header("Content-Disposition: attachment; filename=\"{$filename}\"");
37         header('Expires: 0');
38         header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
39
40         AttachmentAction::sendFile($filepath, $filesize);
41     }
42 }