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