[Web] Shorten and sanitize downloaded file names, fixes too long file names in Firefox

This commit is contained in:
andryyy 2020-05-17 21:27:18 +02:00
parent e824239dee
commit 24bbfb2330
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF

View File

@ -96,7 +96,8 @@ if (!empty($_GET['id']) && ctype_alnum($_GET['id'])) {
}
}
if (isset($_GET['eml'])) {
$dl_filename = str_replace('/', '_', $data['subject']);
$dl_filename = preg_replace('/[^a-z\d]/i', '_', $data['subject']);
$dl_filename = strlen($dl_filename) > 30 ? substr($dl_filename,0,30) : $dl_filename;
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
@ -113,7 +114,8 @@ if (!empty($_GET['id']) && ctype_alnum($_GET['id'])) {
exit(json_encode('Forbidden'));
}
$dl_id = intval($_GET['att']);
$dl_filename = $data['attachments'][$dl_id][0];
$dl_filename = preg_replace('/[^a-z\d]/i', '_', $data['attachments'][$dl_id][0]);
$dl_filename = strlen($dl_filename) > 30 ? substr($dl_filename,0,30) : $dl_filename;
if (!is_dir($tmpdir . $dl_filename) && file_exists($tmpdir . $dl_filename)) {
header('Pragma: public');
header('Expires: 0');