Commit 9c740537 authored by Carsten  Rose's avatar Carsten Rose
Browse files

splitPdf: using 'fileSplit=jpeg' and uploading a PDF with only one page,...

splitPdf: using 'fileSplit=jpeg' and uploading a PDF with only one page, results in split.jpg. Now, split.jpg is renamed internally to split-0.jpg to provide a repair shell script a unified naming scheme.
parent b0bf0e41
Pipeline #1740 passed with stage
in 2 minutes and 19 seconds
......@@ -998,12 +998,7 @@ class Save {
ERROR_PDF2SVG);
}
// Array of created file names.
if (false === ($files = scandir($tempDir))) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Splitted files not found', ERROR_MESSAGE_SUPPORT => "[cwd=$cwd] scandir(.)" . HelperFile::errorGetLastAsString()]),
ERROR_PDF2JPEG);
}
$files = Helperfile::getSplitFileNames($tempDir);
$xId = $this->store->getVar(COLUMN_ID, STORE_RECORD);
......
......@@ -120,11 +120,11 @@ class HelperFile {
return $vars;
}
try {
$vars[VAR_FILE_MIME_TYPE] = self::getMimeType($pathFileName);
$vars[VAR_FILE_SIZE] = filesize($pathFileName);
} catch (Exception $e) {
// do nothing
$vars[VAR_FILE_MIME_TYPE] = self::getMimeType($pathFileName);
$vars[VAR_FILE_SIZE] = filesize($pathFileName);
if ($vars[VAR_FILE_SIZE] === false) {
$vars[VAR_FILE_SIZE] = '-';
}
return $vars;
......@@ -482,6 +482,39 @@ class HelperFile {
return '';
}
/**
* Get array of split file names. Remove '.', '..', QFQ_TEMP_SOURCE.
* @param $dir
* @return array
* @throws UserFormException
*/
public static function getSplitFileNames($dir) {
// Array of created file names.
if (false === ($files = scandir($dir))) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Splitted files not found', ERROR_MESSAGE_SUPPORT => "[cwd=$dir] scandir(.)" . HelperFile::errorGetLastAsString()]),
ERROR_PDF2JPEG);
}
$new = Array();
foreach ($files as $key => $value) {
if ($value == '.' || $value == '..' || $value == QFQ_TEMP_SOURCE) {
continue;
}
// IM 'convert' use a strange auto numbering: if there is only one page: split.jpg, if there are multiple pages, first: split-0.jpg, ....
if ($value == 'split.jpg') {
$value = 'split-0.jpg';
self::rename($dir . '/' . $files[$key], $dir . '/' . $value);
}
$new[] = $value;
}
return $new;
}
}
Markdown is supported
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