]> git.mxchange.org Git - friendica.git/blob - mod/attach.php
Just some more fixed notice
[friendica.git] / mod / attach.php
1 <?php
2 /**
3  * @file mod/attach.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\L10n;
8 use Friendica\Database\dba;
9 use Friendica\Database\DBM;
10
11 require_once 'include/dba.php';
12 require_once 'include/security.php';
13
14 function attach_init(App $a)
15 {
16         if ($a->argc != 2) {
17                 notice(L10n::t('Item not available.') . EOL);
18                 return;
19         }
20
21         $item_id = intval($a->argv[1]);
22
23         // Check for existence, which will also provide us the owner uid
24
25         $r = dba::selectFirst('attach', [], ['id' => $item_id]);
26         if (!DBM::is_result($r)) {
27                 notice(L10n::t('Item was not found.'). EOL);
28                 return;
29         }
30
31         $sql_extra = permissions_sql($r['uid']);
32
33         // Now we'll see if we can access the attachment
34
35         $r = q("SELECT * FROM `attach` WHERE `id` = '%d' $sql_extra LIMIT 1",
36                 dbesc($item_id)
37         );
38
39         if (!DBM::is_result($r)) {
40                 notice(L10n::t('Permission denied.') . EOL);
41                 return;
42         }
43
44         // Use quotes around the filename to prevent a "multiple Content-Disposition"
45         // error in Chrome for filenames with commas in them
46         header('Content-type: ' . $r[0]['filetype']);
47         header('Content-length: ' . $r[0]['filesize']);
48         if (isset($_GET['attachment']) && $_GET['attachment'] === '0') {
49                 header('Content-disposition: filename="' . $r[0]['filename'] . '"');
50         } else {
51                 header('Content-disposition: attachment; filename="' . $r[0]['filename'] . '"');
52         }
53
54         echo $r[0]['data'];
55         killme();
56         // NOTREACHED
57 }