Skip to content

Commit 0a7f7b4

Browse files
sammarshalloumatthewhilton
authored andcommitted
Remove use of utf8_encode (deprecated in PHP 8.2)
1 parent 714963a commit 0a7f7b4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

classes/local/store/s3/client.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,13 @@ private function get_nice_filename($headers) {
670670

671671
if (!empty($originalfilename)) {
672672
$result['Content-Disposition'] = $contentdisposition;
673-
$result['filename'] = 'filename="' . utf8_encode($originalfilename) . '"';
673+
// The filename parameter must be in ISO-8859-1, however it works in browsers if
674+
// you treat the original UTF-8 string as ISO-8859-1 characters. To achieve that
675+
// here, we encode the UTF-8 as if it were ISO-8859-1. This behaviour is hideous
676+
// so it would be nice to use the optional filename* field (RFC 5987) but S3 still
677+
// complains if we do that.
678+
$jankyfilename = \core_text::convert($originalfilename, 'ISO-8859-1');
679+
$result['filename'] = 'filename="' . $jankyfilename . '"';
674680
$result['Content-Type'] = $originalcontenttype;
675681
}
676682
}

0 commit comments

Comments
 (0)