From 6ae32fc3d73c236857b2f110e0fe5c458420ad1c Mon Sep 17 00:00:00 2001 From: tianshujie Date: Thu, 26 Sep 2024 09:44:39 +0800 Subject: [PATCH] * [task#128952,doing,0.5h] fix filename error under the Safari browser. --- module/file/model.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/module/file/model.php b/module/file/model.php index a9a224ecb6..29f8c35317 100755 --- a/module/file/model.php +++ b/module/file/model.php @@ -976,10 +976,21 @@ class fileModel extends model /* Judge the content type. */ $mimes = $this->config->file->mimes; $contentType = isset($mimes[$fileType]) ? $mimes[$fileType] : $mimes['default']; - $fileName = str_replace('+', ' ', urlencode($fileName)); + + /* Safari浏览器下载文件名乱码问题。 */ + if($fileType != 'zip' && preg_match("/Safari/", $_SERVER["HTTP_USER_AGENT"])) + { + $fileName = rawurlencode($fileName); + $attachment = 'attachment; filename*=utf-8\'\'' . $fileName; + } + else + { + $fileName = str_replace("+", "%20", urlencode($fileName)); + $attachment = "attachment; filename=\"{$fileName}\";"; + } helper::header('Content-type', $contentType); - helper::header('Content-Disposition', "attachment; filename=\"$fileName\""); + helper::header('Content-Disposition', $attachment); helper::header('Pragma', 'no-cache'); helper::header('Expires', '0'); if($type == 'content') helper::end($content);