This commit is contained in:
Marcin Kurczewski 2013-10-13 13:37:18 +02:00
parent cc57b8b8a0
commit e33ec7abe7
2 changed files with 22 additions and 1 deletions

View file

@ -721,6 +721,7 @@ class PostController
{ {
$this->context->layoutName = 'layout-file'; $this->context->layoutName = 'layout-file';
$post = self::locatePost($name); $post = self::locatePost($name);
R::preload($post, ['tag']);
PrivilegesHelper::confirmWithException($this->context->user, Privilege::RetrievePost); PrivilegesHelper::confirmWithException($this->context->user, Privilege::RetrievePost);
PrivilegesHelper::confirmWithException($this->context->user, Privilege::RetrievePost, PostSafety::toString($post->safety)); PrivilegesHelper::confirmWithException($this->context->user, Privilege::RetrievePost, PostSafety::toString($post->safety));
@ -731,6 +732,16 @@ class PostController
if (!is_readable($path)) if (!is_readable($path))
throw new SimpleException('Post file is not readable'); throw new SimpleException('Post file is not readable');
$ext = substr($post->orig_name, strrpos($post->orig_name, '.') + 1);
if (strpos($post->orig_name, '.') === false)
$ext = '.dat';
$fn = sprintf('%s_%s_%s.%s',
$this->config->main->title,
$post->id, join(',', array_map(function($tag) { return $tag->name; }, $post->sharedTag)),
$ext);
$fn = preg_replace('/[[:^print:]]/', '', $fn);
$this->context->transport->customFileName = $fn;
$this->context->transport->mimeType = $post->mimeType; $this->context->transport->mimeType = $post->mimeType;
$this->context->transport->filePath = $path; $this->context->transport->filePath = $path;
} }

View file

@ -6,7 +6,17 @@ if (!empty($this->context->transport->errorMessage))
} }
else else
{ {
\Chibi\HeadersHelper::set('Content-Type', $this->context->transport->mimeType); if (isset($this->context->transport->customFileName))
{
\Chibi\HeadersHelper::set(
'Content-Disposition',
'inline; filename=' . $this->context->transport->customFileName);
}
\Chibi\HeadersHelper::set(
'Content-Type',
$this->context->transport->mimeType);
readfile($this->context->transport->filePath); readfile($this->context->transport->filePath);
flush(); flush();
} }