]> git.mxchange.org Git - friendica.git/blob - mod/attach.php
add remove_user hook (it looks like dreamhost changed all my file permissions, this...
[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         header('Content-type: ' . $r[0]['filetype']);
38         header('Content-disposition: attachment; filename=' . $r[0]['filename']);
39         echo $r[0]['data'];
40         killme();
41         // NOTREACHED
42 }