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