streams/mod/attach.php

53 lines
1.1 KiB
PHP
Raw Normal View History

2011-05-25 09:08:15 +00:00
<?php
require_once('include/security.php');
require_once('include/attach.php');
2011-05-25 09:08:15 +00:00
function attach_init(&$a) {
if(argc() < 2) {
2011-05-25 09:08:15 +00:00
notice( t('Item not available.') . EOL);
return;
}
$r = attach_by_hash(argv(1),((argc() > 2) ? intval(argv(2)) : 0));
2011-05-25 09:08:15 +00:00
if(! $r['success']) {
notice( $r['message'] . EOL);
2011-05-25 09:08:15 +00:00
return;
}
$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'])
);
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'] . '"');
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');
$ostream = fopen('php://output','wb');
if($istream && $ostream) {
pipe_streams($istream,$ostream);
fclose($istream);
fclose($ostream);
}
}
else
2015-04-13 23:18:11 +00:00
echo dbunescbin($r['data']['data']);
2011-05-25 09:08:15 +00:00
killme();
}