Commit c700ce0d authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fixed exportFilename extension behaviour.

Link.php: If there is no output filename defined, the default is now computed in Download.php, not in Link.php as before.
Download.php: Extract filename extension from mimetype, compare it with output filename, if it does not match, append the computed extension. This forces the filemanager to open the correct application after download.
parent f16903a1
......@@ -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.
......
......@@ -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
......
......@@ -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;
......
......@@ -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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment