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