diff --git a/extension/Documentation/Manual.rst b/extension/Documentation/Manual.rst index 87fca0ba632f1a1918142f94fc6739f2a200a8a5..01b273f24b6dd0d02401def86a17796f04da3509 100644 --- a/extension/Documentation/Manual.rst +++ b/extension/Documentation/Manual.rst @@ -3477,8 +3477,11 @@ Parameter and (element) sources * *download*: `d[:<exportFilename>]` - * *exportFilename* = <filename for save as> - Name, offered in the 'File save as' browser dialog. Default: 'output.pdf'. - The user typically expect meaningfull and distinct filenames for different download links. + * *exportFilename* = <filename for save as> - Name, offered in the 'File save as' browser dialog. Default: 'output.<ext>'. + If there is no `exportFilename` defined and `mode=file`, than the original filename is taken. If the mimetype is + different from the `exportFilename` extension, then the mimetype extension will be added to `exportFilename`. This + guarantees that a filemanager will open the file with the correct application. + The user typically expect meaningful and distinct filenames for different download links. * *popupMessage*: `a:<text>` - will be displayed in the popup window during download. If the creating/download is fast, the window might disapear quicly. diff --git a/extension/qfq/qfq/Constants.php b/extension/qfq/qfq/Constants.php index 18c5bb6ee7e3b15b19b97f8494e74ce2099e07dc..d16ef3c400b365cbd1f93cd91784daf712be5f20 100644 --- a/extension/qfq/qfq/Constants.php +++ b/extension/qfq/qfq/Constants.php @@ -867,7 +867,7 @@ const DOWNLOAD_MODE_EXCEL = 'excel'; const DOWNLOAD_MODE_ZIP = 'zip'; const DOWNLOAD_EXPORT_FILENAME = '_exportFilename'; const DOWNLOAD_FILE_PREFIX = 'qfq.temp'; // temporary filename on server of single export file -const DOWNLOAD_OUTPUT_PDF = 'output.pdf'; +const DOWNLOAD_OUTPUT_PDF = 'output'; // HTML2PDF diff --git a/extension/qfq/qfq/report/Download.php b/extension/qfq/qfq/report/Download.php index 59b6c08af3183ba214826c39c04b2e73387d1328..6b4f0bc6dea362a37be337cd45e82d97da018da7 100644 --- a/extension/qfq/qfq/report/Download.php +++ b/extension/qfq/qfq/report/Download.php @@ -115,8 +115,15 @@ class Download { */ private function outputFile($filename, $outputFilename) { - $mimetype = mime_content_type($filename); $length = filesize($filename); + $mimetype = mime_content_type($filename); + + // In case there is a wrong filenameextension on the outputFilename: extend it. + $ext = '.' . substr($mimetype, strrpos($mimetype, '/') + 1); + $len = strlen($ext); + if (substr($outputFilename, 0 - $len) != $ext) { + $outputFilename .= $ext; + } header("Content-type: $mimetype"); header("Content-Length: $length"); @@ -232,7 +239,6 @@ class Download { throw new DownloadException ("Error chdir($workDir)", ERROR_IO_CHDIR); } - $exportFilename = empty($vars[DOWNLOAD_EXPORT_FILENAME]) ? DOWNLOAD_OUTPUT_PDF : $vars[DOWNLOAD_EXPORT_FILENAME]; $downloadMode = $vars[DOWNLOAD_MODE]; $elements = explode(PARAM_DELIMITER, $vars[SIP_DOWNLOAD_PARAMETER]); @@ -253,6 +259,9 @@ class Download { case DOWNLOAD_MODE_FILE: $filename = $tmpFiles[0]; + if (empty($vars[DOWNLOAD_EXPORT_FILENAME])) { + $vars[DOWNLOAD_EXPORT_FILENAME] = substr($filename, strpos($filename, '/')); + } break; case DOWNLOAD_MODE_PDF: @@ -264,6 +273,8 @@ class Download { break; } + $exportFilename = empty($vars[DOWNLOAD_EXPORT_FILENAME]) ? DOWNLOAD_OUTPUT_PDF : $vars[DOWNLOAD_EXPORT_FILENAME]; + $this->outputFile($filename, $exportFilename); $tmpFiles[] = $filename; diff --git a/extension/qfq/qfq/report/Link.php b/extension/qfq/qfq/report/Link.php index 05f549aed692df523430079c6cc3f3366a4f7b89..15034554c0ade8e8327e6d73a8b28d5c90b879fb 100644 --- a/extension/qfq/qfq/report/Link.php +++ b/extension/qfq/qfq/report/Link.php @@ -1127,7 +1127,7 @@ EOF; $vars[NAME_URL] = API_DIR . '/' . API_DOWNLOAD_PHP; $vars[NAME_LINK_CLASS_DEFAULT] = NO_CLASS; $vars[NAME_EXTRA_CONTENT_WRAP] = '<button type="button" ' . $attributes . $onClick . '>'; - $vars[NAME_DOWNLOAD] = ($value == '') ? DOWNLOAD_OUTPUT_PDF : $value; // Download ExportFileName +// $vars[NAME_DOWNLOAD] = ($value == '') ? DOWNLOAD_OUTPUT_PDF : $value; // Download ExportFileName return $vars; }