truncate filenames to 250 chars, fixes #931

This commit is contained in:
Shish 2023-07-03 15:09:38 +01:00
parent f7f0c11ee8
commit 016a5d240b

View file

@ -80,6 +80,12 @@ class BasePage
*/ */
public function set_filename(string $filename, string $disposition = "attachment"): void public function set_filename(string $filename, string $disposition = "attachment"): void
{ {
$max_len = 250;
if(strlen($filename) > $max_len) {
// remove extension, truncate filename, apply extension
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$filename = substr($filename, 0, $max_len - strlen($ext) - 1) . '.' . $ext;
}
$this->filename = $filename; $this->filename = $filename;
$this->disposition = $disposition; $this->disposition = $disposition;
} }