mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/14285] Add filename fallback
PHPBB3-14285
This commit is contained in:
parent
6e345c37a9
commit
278d4d8318
1 changed files with 15 additions and 3 deletions
|
@ -254,14 +254,16 @@ class attachment extends controller
|
|||
{
|
||||
$disposition = $this->response->headers->makeDisposition(
|
||||
ResponseHeaderBag::DISPOSITION_INLINE,
|
||||
rawurlencode(htmlspecialchars_decode($attachment['real_filename']))
|
||||
$attachment['real_filename'],
|
||||
$this->filenameFallback($attachment['real_filename'])
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$disposition = $this->response->headers->makeDisposition(
|
||||
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
|
||||
rawurlencode(htmlspecialchars_decode($attachment['real_filename']))
|
||||
$attachment['real_filename'],
|
||||
$this->filenameFallback($attachment['real_filename'])
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -274,12 +276,22 @@ class attachment extends controller
|
|||
return parent::handle($attachment['physical_filename']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove non valid characters https://github.com/symfony/http-foundation/commit/c7df9082ee7205548a97031683bc6550b5dc9551
|
||||
*/
|
||||
protected function filenameFallback($filename)
|
||||
{
|
||||
$filename = preg_replace(['/[^\x20-\x7e]/', '/%/', '/\//', '/\\\/'], '', $filename);
|
||||
|
||||
return (!empty($filename)) ?: 'File';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function prepare($file)
|
||||
{
|
||||
$this->response->setPivate(); // But default should be private, but make sure of it
|
||||
$this->response->setPrivate(); // But default should be private, but make sure of it
|
||||
|
||||
parent::prepare($file);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue