add extension to temp file, because this is needed for programms like unoconv

This commit is contained in:
Uwe Steinmann 2021-10-08 13:10:24 +02:00
parent 9734d57ff3
commit 31db5f69fe

View File

@ -126,11 +126,6 @@ class SeedDMS_ConversionServiceExec extends SeedDMS_ConversionServiceBase {
/* if no %f placeholder is found, we assume output to stdout */
$tostdout = strpos($this->cmd, '%o') === false;
$start = microtime(true);
if(!$target && !$tostdout)
$tmpfile = tempnam(sys_get_temp_dir(), 'convert');
else
$tmpfile = $target;
$format = '';
switch($this->to) {
case 'image/gif':
@ -143,7 +138,22 @@ class SeedDMS_ConversionServiceExec extends SeedDMS_ConversionServiceBase {
case 'image/png':
$format = 'png';
break;
case 'application/pdf':
$format = 'pdf';
break;
}
$start = microtime(true);
$hastempfile = false;
if(!$target && !$tostdout) {
$tmpfile = tempnam(sys_get_temp_dir(), 'convert');
/* Some programms (e.g. unoconv) need the output file to have the
* right extension. Without an extension it will add one by itself.
*/
if($format)
rename($tmpfile, $tmpfile .= '.'.$format);
$hastempfile = true;
} else
$tmpfile = $target;
/* %s was just added because the commands to convert to text/plain used
* it instead of %f for the input file
* %f = input file
@ -151,10 +161,12 @@ class SeedDMS_ConversionServiceExec extends SeedDMS_ConversionServiceBase {
* %m = mime type
* %w = width
*/
$cmd = str_replace(array('%w', '%f', '%s', '%if', '%o', '%m'), array(isset($params['width']) ? $params['width'] : '150', $infile, $infile, $format, $tmpfile, $this->from), $this->cmd);
$cmd = str_replace(array('%w', '%f', '%s', '%if', '%o', '%m'), array(!empty($params['width']) ? (int) $params['width'] : '150', $infile, $infile, $format, $tmpfile, $this->from), $this->cmd);
try {
$ret = self::execWithTimeout($cmd, $this->timeout);
} catch(Exception $e) {
if($hastempfile)
unlink($tmpfile);
return false;
}
$end = microtime(true);