]> git.mxchange.org Git - friendica.git/blob - mod/attach.php
Merge pull request #581 from fermionic/20130112-backport-red-smarty-improvements
[friendica.git] / mod / attach.php
1 <?php
2
3 require_once('include/security.php');
4
5 function attach_init(&$a) {
6
7         if($a->argc != 2) {
8                 notice( t('Item not available.') . EOL);
9                 return;
10         }
11
12         $item_id = intval($a->argv[1]);
13
14         // Check for existence, which will also provide us the owner uid
15
16         $r = q("SELECT * FROM `attach` WHERE `id` = %d LIMIT 1",
17                 intval($item_id)
18         );
19         if(! count($r)) {
20                 notice( t('Item was not found.'). EOL);
21                 return;
22         }
23
24         $sql_extra = permissions_sql($r[0]['uid']);
25
26         // Now we'll see if we can access the attachment
27
28         $r = q("SELECT * FROM `attach` WHERE `id` = '%d' $sql_extra LIMIT 1",
29                 dbesc($item_id)
30         );
31
32         if(! count($r)) {
33                 notice( t('Permission denied.') . EOL);
34                 return;
35         }
36
37         // Use quotes around the filename to prevent a "multiple Content-Disposition"
38         // error in Chrome for filenames with commas in them
39         header('Content-type: ' . $r[0]['filetype']);
40         header('Content-disposition: attachment; filename="' . $r[0]['filename'] . '"');
41         echo $r[0]['data'];
42         killme();
43         // NOTREACHED
44 }