]> git.mxchange.org Git - friendica.git/blob - mod/attach.php
6155a3f99e9853c723acd623c64a375367eeb9b0
[friendica.git] / mod / attach.php
1 <?php
2
3 use Friendica\App;
4
5 require_once('include/security.php');
6
7 function attach_init(App $a) {
8
9         if($a->argc != 2) {
10                 notice( t('Item not available.') . EOL);
11                 return;
12         }
13
14         $item_id = intval($a->argv[1]);
15
16         // Check for existence, which will also provide us the owner uid
17
18         $r = q("SELECT * FROM `attach` WHERE `id` = %d LIMIT 1",
19                 intval($item_id)
20         );
21         if (! dbm::is_result($r)) {
22                 notice( t('Item was not found.'). EOL);
23                 return;
24         }
25
26         $sql_extra = permissions_sql($r[0]['uid']);
27
28         // Now we'll see if we can access the attachment
29
30         $r = q("SELECT * FROM `attach` WHERE `id` = '%d' $sql_extra LIMIT 1",
31                 dbesc($item_id)
32         );
33
34         if (! dbm::is_result($r)) {
35                 notice( t('Permission denied.') . EOL);
36                 return;
37         }
38
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'] . '"');
45         else
46                 header('Content-disposition: attachment; filename="' . $r[0]['filename'] . '"');
47
48         echo $r[0]['data'];
49         killme();
50         // NOTREACHED
51 }