Skip to content

Commit 9e0101e

Browse files
committed
Remove use of utf8_encode (deprecated in PHP 8.2)
1 parent 789d092 commit 9e0101e

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

classes/local/store/s3/client.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,14 @@ private function get_nice_filename($headers) {
604604

605605
if (!empty($originalfilename)) {
606606
$result['Content-Disposition'] = $contentdisposition;
607-
$result['filename'] = 'filename="' . utf8_encode($originalfilename) . '"';
607+
// The filename parameter must be in ISO-8859-1, however it works in browsers if
608+
// you treat the original UTF-8 string as ISO-8859-1 characters. To achieve that
609+
// here, we encode the UTF-8 as if it were ISO-8859-1. Because this behaviour is
610+
// hideous, we also supply the original UTF-8 as the optional 'filename*' field
611+
// which is supposed to take precedence, and supports a specified encoding.
612+
$jankyfilename = \core_text::convert($originalfilename, 'ISO-8859-1');
613+
$result['filename'] = 'filename="' . $jankyfilename .
614+
'"; filename*=UTF-8\'\'"' . $originalfilename . '"';
608615
$result['Content-Type'] = $originalcontenttype;
609616
}
610617
}

0 commit comments

Comments
 (0)