6 use Friendica\Core\L10n;
7 use Friendica\Database\DBM;
9 require_once 'include/dba.php';
10 require_once 'include/security.php';
12 function attach_init(App $a)
15 notice(L10n::t('Item not available.') . EOL);
19 $item_id = intval($a->argv[1]);
21 // Check for existence, which will also provide us the owner uid
23 $r = dba::selectFirst('attach', [], ['id' => $item_id]);
24 if (!DBM::is_result($r)) {
25 notice(L10n::t('Item was not found.'). EOL);
29 $sql_extra = permissions_sql($r['uid']);
31 // Now we'll see if we can access the attachment
33 $r = q("SELECT * FROM `attach` WHERE `id` = '%d' $sql_extra LIMIT 1",
37 if (!DBM::is_result($r)) {
38 notice(L10n::t('Permission denied.') . EOL);
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'] . '"');
49 header('Content-disposition: attachment; filename="' . $r[0]['filename'] . '"');