4 use Friendica\Database\DBM;
6 require_once('include/security.php');
8 function attach_init(App $a) {
11 notice( t('Item not available.') . EOL);
15 $item_id = intval($a->argv[1]);
17 // Check for existence, which will also provide us the owner uid
19 $r = q("SELECT * FROM `attach` WHERE `id` = %d LIMIT 1",
22 if (! DBM::is_result($r)) {
23 notice( t('Item was not found.'). EOL);
27 $sql_extra = permissions_sql($r[0]['uid']);
29 // Now we'll see if we can access the attachment
31 $r = q("SELECT * FROM `attach` WHERE `id` = '%d' $sql_extra LIMIT 1",
35 if (! DBM::is_result($r)) {
36 notice( t('Permission denied.') . EOL);
40 // Use quotes around the filename to prevent a "multiple Content-Disposition"
41 // error in Chrome for filenames with commas in them
42 header('Content-type: ' . $r[0]['filetype']);
43 header('Content-length: ' . $r[0]['filesize']);
44 if(isset($_GET['attachment']) && $_GET['attachment'] === '0')
45 header('Content-disposition: filename="' . $r[0]['filename'] . '"');
47 header('Content-disposition: attachment; filename="' . $r[0]['filename'] . '"');