5 require_once('include/security.php');
7 function attach_init(App $a) {
10 notice( t('Item not available.') . EOL);
14 $item_id = intval($a->argv[1]);
16 // Check for existence, which will also provide us the owner uid
18 $r = q("SELECT * FROM `attach` WHERE `id` = %d LIMIT 1",
21 if (! dbm::is_result($r)) {
22 notice( t('Item was not found.'). EOL);
26 $sql_extra = permissions_sql($r[0]['uid']);
28 // Now we'll see if we can access the attachment
30 $r = q("SELECT * FROM `attach` WHERE `id` = '%d' $sql_extra LIMIT 1",
34 if (! dbm::is_result($r)) {
35 notice( t('Permission denied.') . EOL);
39 // Use quotes around the filename to prevent a "multiple Content-Disposition"
40 // error in Chrome for filenames with commas in them
41 header('Content-type: ' . $r[0]['filetype']);
42 header('Content-length: ' . $r[0]['filesize']);
43 if(isset($_GET['attachment']) && $_GET['attachment'] === '0')
44 header('Content-disposition: filename="' . $r[0]['filename'] . '"');
46 header('Content-disposition: attachment; filename="' . $r[0]['filename'] . '"');