From 268d3df98624badbb2ddee71a610ae0b1a4a2d17 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Mon, 19 Feb 2024 15:50:34 +0000 Subject: [PATCH] Remove use of utf8_encode (deprecated in PHP 8.2) --- classes/local/store/s3/client.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/classes/local/store/s3/client.php b/classes/local/store/s3/client.php index 31abe15d..edf32507 100644 --- a/classes/local/store/s3/client.php +++ b/classes/local/store/s3/client.php @@ -667,7 +667,13 @@ private function get_nice_filename($headers) { if (!empty($originalfilename)) { $result['Content-Disposition'] = $contentdisposition; - $result['filename'] = 'filename="' . utf8_encode($originalfilename) . '"'; + // The filename parameter must be in ISO-8859-1, however it works in browsers if + // you treat the original UTF-8 string as ISO-8859-1 characters. To achieve that + // here, we encode the UTF-8 as if it were ISO-8859-1. This behaviour is hideous + // so it would be nice to use the optional filename* field (RFC 5987) but S3 still + // complains if we do that. + $jankyfilename = \core_text::convert($originalfilename, 'ISO-8859-1'); + $result['filename'] = 'filename="' . $jankyfilename . '"'; $result['Content-Type'] = $originalcontenttype; } }