2011-05-25 09:08:15 +00:00
|
|
|
<?php
|
|
|
|
|
2011-07-01 00:35:35 +00:00
|
|
|
require_once('include/security.php');
|
2013-02-01 00:13:44 +00:00
|
|
|
require_once('include/attach.php');
|
2011-07-01 00:35:35 +00:00
|
|
|
|
2011-05-25 09:08:15 +00:00
|
|
|
function attach_init(&$a) {
|
|
|
|
|
2013-02-01 00:13:44 +00:00
|
|
|
if(argc() < 2) {
|
2011-05-25 09:08:15 +00:00
|
|
|
notice( t('Item not available.') . EOL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-01 00:13:44 +00:00
|
|
|
$r = attach_by_hash(argv(1),((argc() > 2) ? intval(argv(2)) : 0));
|
2011-05-25 09:08:15 +00:00
|
|
|
|
2013-02-01 00:13:44 +00:00
|
|
|
if(! $r['success']) {
|
|
|
|
notice( $r['message'] . EOL);
|
2011-05-25 09:08:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-09 02:06:52 +00:00
|
|
|
$c = q("select channel_address from channel where channel_id = %d limit 1",
|
2014-01-09 04:58:58 +00:00
|
|
|
intval($r['data']['uid'])
|
2014-01-09 02:06:52 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if(! $c)
|
|
|
|
return;
|
|
|
|
|
2014-02-09 23:00:47 +00:00
|
|
|
|
|
|
|
$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']);
|
|
|
|
}
|
|
|
|
|
2014-01-29 22:11:36 +00:00
|
|
|
header('Content-disposition: attachment; filename="' . $r['data']['filename'] . '"');
|
2014-01-07 02:13:02 +00:00
|
|
|
if($r['data']['flags'] & ATTACH_FLAG_OS ) {
|
2015-04-13 23:18:11 +00:00
|
|
|
$fname = dbunescbin($r['data']['data']);
|
|
|
|
$istream = fopen('store/' . $c[0]['channel_address'] . '/' . $fname,'rb');
|
2014-01-11 20:58:00 +00:00
|
|
|
$ostream = fopen('php://output','wb');
|
|
|
|
if($istream && $ostream) {
|
|
|
|
pipe_streams($istream,$ostream);
|
|
|
|
fclose($istream);
|
|
|
|
fclose($ostream);
|
2014-01-07 02:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-05 23:34:30 +00:00
|
|
|
else
|
2015-04-13 23:18:11 +00:00
|
|
|
echo dbunescbin($r['data']['data']);
|
2011-05-25 09:08:15 +00:00
|
|
|
killme();
|
2013-02-01 00:13:44 +00:00
|
|
|
|
2014-01-29 20:38:32 +00:00
|
|
|
}
|