From ef9310d1e7cf8db1248ba6d0a5faabd3c24a26c0 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 14 Nov 2022 15:18:48 +0000 Subject: [PATCH] MDL-76273 core: multi-byte character filename support for TCPDF. See: https://github.com/tecnickcom/TCPDF/pull/562 --- lib/tcpdf/readme_moodle.txt | 1 + lib/tcpdf/tcpdf.php | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/tcpdf/readme_moodle.txt b/lib/tcpdf/readme_moodle.txt index 974371cb766..aff58cba7cc 100644 --- a/lib/tcpdf/readme_moodle.txt +++ b/lib/tcpdf/readme_moodle.txt @@ -6,6 +6,7 @@ Description of TCPDF library import 6.3.5 * remove all fonts that were not already present * visit http://127.0.0.1/lib/tests/other/pdflibtestpage.php and view the pdf * modify getTCPDFProducer lib/tcpdf/include/tcpdf_static.php to remove the version number +* modify `TCPDF::Output` method for multi-byte character filename support (see https://github.com/tecnickcom/TCPDF/pull/562) Important --------- diff --git a/lib/tcpdf/tcpdf.php b/lib/tcpdf/tcpdf.php index 7a6cb50f022..fefa3844a48 100644 --- a/lib/tcpdf/tcpdf.php +++ b/lib/tcpdf/tcpdf.php @@ -7604,7 +7604,7 @@ class TCPDF { * Send the document to a given destination: string, local file or browser. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.
* The method first calls Close() if necessary to terminate the document. - * @param $name (string) The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character. + * @param $name (string) The name of the file when saved * @param $dest (string) Destination where to send the document. It can take one of the following values: * @return string * @public @@ -7622,10 +7622,7 @@ class TCPDF { $dest = $dest ? 'D' : 'F'; } $dest = strtoupper($dest); - if ($dest[0] != 'F') { - $name = preg_replace('/[\s]+/', '_', $name); - $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name); - } + if ($this->sign) { // *** apply digital signature to the document *** // get the document content @@ -7696,7 +7693,8 @@ class TCPDF { header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); - header('Content-Disposition: inline; filename="'.basename($name).'"'); + header('Content-Disposition: inline; filename="' . rawurlencode(basename($name)) . '"; ' . + 'filename*=UTF-8\'\'' . rawurlencode(basename($name))); TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen); } else { echo $this->getBuffer(); @@ -7727,7 +7725,8 @@ class TCPDF { header('Content-Type: application/pdf'); } // use the Content-Disposition header to supply a recommended filename - header('Content-Disposition: attachment; filename="'.basename($name).'"'); + header('Content-Disposition: attachment; filename="' . rawurlencode(basename($name)) . '"; ' . + 'filename*=UTF-8\'\'' . rawurlencode(basename($name))); header('Content-Transfer-Encoding: binary'); TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen); break;