From 016a5d240b893a782f67af868801dd2e8861a756 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 3 Jul 2023 15:09:38 +0100 Subject: [PATCH] truncate filenames to 250 chars, fixes #931 --- core/basepage.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/basepage.php b/core/basepage.php index acfc094e..c644dfbd 100644 --- a/core/basepage.php +++ b/core/basepage.php @@ -80,6 +80,12 @@ class BasePage */ 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->disposition = $disposition; }