diff options
author | Wave <wave72@users.noreply.github.com> | 2016-07-22 10:55:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-22 10:55:02 +0200 |
commit | 744ad84714fe0f7a3d90250a4ff02dc4327b9061 (patch) | |
tree | 595fb74ec9ea0bc7130d18bd7993d719a222d343 /Zotlabs/Module/Attach.php | |
parent | c38c79d71c8ef70ef649f83e322f1984b75ee2dd (diff) | |
parent | 7d897a3f03bd57ed556433eb84a41963ba44e02e (diff) | |
download | volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.tar.gz volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.tar.bz2 volse-hubzilla-744ad84714fe0f7a3d90250a4ff02dc4327b9061.zip |
Merge pull request #6 from redmatrix/dev
Dev
Diffstat (limited to 'Zotlabs/Module/Attach.php')
-rw-r--r-- | Zotlabs/Module/Attach.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Zotlabs/Module/Attach.php b/Zotlabs/Module/Attach.php new file mode 100644 index 000000000..de941d52c --- /dev/null +++ b/Zotlabs/Module/Attach.php @@ -0,0 +1,61 @@ +<?php +namespace Zotlabs\Module; + +require_once('include/security.php'); +require_once('include/attach.php'); + + +class Attach extends \Zotlabs\Web\Controller { + + function init() { + + if(argc() < 2) { + notice( t('Item not available.') . EOL); + return; + } + + $r = attach_by_hash(argv(1),((argc() > 2) ? intval(argv(2)) : 0)); + + if(! $r['success']) { + notice( $r['message'] . EOL); + return; + } + + $c = q("select channel_address from channel where channel_id = %d limit 1", + intval($r['data']['uid']) + ); + + if(! $c) + return; + + + $unsafe_types = array('text/html','text/css','application/javascript'); + + if(in_array($r['data']['filetype'],$unsafe_types)) { + header('Content-type: text/plain'); + } + else { + header('Content-type: ' . $r['data']['filetype']); + } + + header('Content-disposition: attachment; filename="' . $r['data']['filename'] . '"'); + if(intval($r['data']['os_storage'])) { + $fname = dbunescbin($r['data']['content']); + if(strpos($fname,'store') !== false) + $istream = fopen($fname,'rb'); + else + $istream = fopen('store/' . $c[0]['channel_address'] . '/' . $fname,'rb'); + $ostream = fopen('php://output','wb'); + if($istream && $ostream) { + pipe_streams($istream,$ostream); + fclose($istream); + fclose($ostream); + } + } + else + echo dbunescbin($r['data']['content']); + killme(); + + } + +} |