streams/Zotlabs/Module/Attach.php

59 lines
1.5 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2021-12-03 03:01:39 +00:00
2016-04-19 03:38:38 +00:00
namespace Zotlabs\Module;
2021-12-02 22:33:36 +00:00
use Zotlabs\Web\Controller;
2016-04-19 03:38:38 +00:00
require_once('include/security.php');
require_once('include/attach.php');
2021-12-02 23:02:31 +00:00
class Attach extends Controller
{
public function init()
{
if (argc() < 2) {
notice(t('Item not available.') . EOL);
return;
}
$r = attach_by_hash(argv(1), get_observer_hash(), ((argc() > 2) ? intval(argv(2)) : 0));
if (!$r['success']) {
notice($r['message'] . EOL);
return;
}
2021-12-03 03:01:39 +00:00
$c = q(
"select channel_address from channel where channel_id = %d limit 1",
2021-12-02 23:02:31 +00:00
intval($r['data']['uid'])
);
2021-12-03 03:01:39 +00:00
if (!$c) {
2021-12-02 23:02:31 +00:00
return;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
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']);
2021-12-03 03:01:39 +00:00
if (strpos($fname, 'store') !== false) {
2021-12-02 23:02:31 +00:00
$istream = fopen($fname, 'rb');
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$istream = fopen('store/' . $c[0]['channel_address'] . '/' . $fname, 'rb');
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$ostream = fopen('php://output', 'wb');
if ($istream && $ostream) {
pipe_streams($istream, $ostream);
fclose($istream);
fclose($ostream);
}
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
echo dbunescbin($r['data']['content']);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
killme();
}
2016-04-19 03:38:38 +00:00
}