7 use Friendica\Core\L10n;
8 use Friendica\Database\DBA;
9 use Friendica\Util\Security;
11 function attach_init(App $a)
14 notice(L10n::t('Item not available.') . EOL);
18 $item_id = intval($a->argv[1]);
20 // Check for existence, which will also provide us the owner uid
22 $r = DBA::selectFirst('attach', [], ['id' => $item_id]);
23 if (!DBA::isResult($r)) {
24 notice(L10n::t('Item was not found.'). EOL);
28 $sql_extra = Security::getPermissionsSQLByUserId($r['uid']);
30 // Now we'll see if we can access the attachment
32 $r = q("SELECT * FROM `attach` WHERE `id` = '%d' $sql_extra LIMIT 1",
36 if (!DBA::isResult($r)) {
37 notice(L10n::t('Permission denied.') . EOL);
41 // Use quotes around the filename to prevent a "multiple Content-Disposition"
42 // error in Chrome for filenames with commas in them
43 header('Content-type: ' . $r[0]['filetype']);
44 header('Content-length: ' . $r[0]['filesize']);
45 if (isset($_GET['attachment']) && $_GET['attachment'] === '0') {
46 header('Content-disposition: filename="' . $r[0]['filename'] . '"');
48 header('Content-disposition: attachment; filename="' . $r[0]['filename'] . '"');