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

F4901: implement split with 'convert' (jpeg). Refactor chmod(), unlink(),...

F4901: implement split with 'convert' (jpeg). Refactor chmod(), unlink(), rename(), rmdir(), copy() to use by QFQ version which throws an exception.
parent 4f31433c
Pipeline #1040 passed with stage
in 2 minutes and 13 seconds
......@@ -3570,7 +3570,7 @@ have multiple references to a single file. Therefore this check is just a fallba
.. _Upload simple mode:
Upload simple mode
;;;;;;;;;;;;;;;;;;
''''''''''''''''''
Requires: *'upload'-FormElement.name = 'column name'* of an column in the primary table.
......@@ -3588,7 +3588,7 @@ Multiple 'upload'-FormElements per form are possible. Each of it needs an own ta
.. _Upload advanced mode:
Upload advanced mode
;;;;;;;;;;;;;;;;;;;;
''''''''''''''''''''
Requires: *'upload'-FormElement.name* is unknown as a column in the primary table.
......@@ -3633,23 +3633,26 @@ A typical name for such an 'upload'-FormElement, to show that the name does not
.. _split-pdf-upload:
Split PDF Upload
;;;;;;;;;;;;;;;;
''''''''''''''''
Additional to the upload, it's possible to split the uploaded file (only PDF files) into several SVG files, one file per
page. The split is done via http://www.cityinthesky.co.uk/opensource/pdf2svg/.
Additional to the upload, it's possible to split the uploaded file (only PDF files) into several SVG or JPEG files, one
file per PDF page. The split is done via http://www.cityinthesky.co.uk/opensource/pdf2svg/ or Image Magick `convert`.
* *FormElement.parameter*:
* *fileSplit* = `<type>` - Activate the splitting process. Only possible value: `fileSplit=svg`.
* *fileDestinationSplit* = `<pathFileName (pattern)>` - Target directory and filename pattern for the created & split'ed files. E.g. ::
* *fileSplit* = `<type>` - Activate the splitting process. Possible values: `svg` or `jpeg`. No default.
* *fileDestinationSplit* = `<pathFileName (pattern)>` - Target directory and filename pattern for the created &
split'ed files. Default <fileDestination>.split/split.<nr>.<fileSplit>
If explicit given, respect that SVG needs a printf style for <nr>, whereas JPEG is numbered automatically. E.g. ::
fileDestinationSplit = fileadmin/protected/{{id:R}}.{{filenameBase}}.%02d.svg
[svg] fileDestinationSplit = fileadmin/protected/{{id:R}}.{{filenameBase:V}}.%02d.svg
[jpeg] fileDestinationSplit = fileadmin/protected/{{id:R}}.{{filenameBase:V}}.jpg
* *tableNameSplit* = `<tablename>` - Reference in table 'Split' to the table, which holds the original PDF file.
* *tableNameSplit* = `<tablename>` - Default: name of table of current form. This name will be saved in table `Split`
The splitting happens immediately after the user pressed save.
The splitting happens immediately after the user pressed `save`.
To easily access the split files via QFQ, per file per record is created in table 'Split'.
To easily access the split files via QFQ, per file one record is created in table 'Split'.
Table 'Split':
......@@ -3664,8 +3667,6 @@ Table 'Split':
+--------------+--------------------------------------------------------------------------------------------+
| pathFileName | Path/filename reference to one of the created files |
+--------------+--------------------------------------------------------------------------------------------+
| created | Timestamp |
+--------------+--------------------------------------------------------------------------------------------+
One usecase why to split an upload: annotate individual pages by using the `FormElement`.type=`annotate`.
......
......@@ -214,6 +214,7 @@ const ERROR_STORE_KEY_EXIST = 1201;
// I/O Error
const ERROR_IO_READ_FILE = 1300;
const ERROR_IO_COPY = 1301;
const ERROR_IO_RMDIR = 1302;
const ERROR_IO_WRITE = 1303;
const ERROR_IO_OPEN = 1304;
const ERROR_IO_UNLINK = 1305;
......@@ -227,6 +228,7 @@ const ERROR_IO_COPY_FILE = 1312;
const ERROR_IO_FILE_NOT_FOUND = 1313;
const ERROR_IO_CHMOD = 1314;
const ERROR_PDF2SVG = 1315;
const ERROR_PDF2JPEG = 1316;
//Report
const ERROR_UNKNOWN_LINK_QUALIFIER = 1400;
......@@ -980,6 +982,7 @@ const FE_FILE_MAX_FILE_SIZE = 'maxFileSize'; // Target pathFilename for an uploa
const FE_FILE_CAPTURE = 'capture'; // On a smartphone opens the camera
const FE_FILE_SPLIT = 'fileSplit';
const FE_FILE_SPLIT_SVG = 'svg';
const FE_FILE_SPLIT_JPEG = 'jpeg';
const FE_FILE_SPLIT_TABLE_NAME = 'tableNameSplit';
const FE_FILE_DOWNLOAD_BUTTON = 'downloadButton';
const FE_FILE_AUTO_ORIENT = 'autoOrient';
......@@ -1214,9 +1217,13 @@ const UPLOAD_MODE_DELETEOLD = 'deleteOld';
const UPLOAD_MODE_DELETEOLD_NEW = 'deleteOld+new';
const UPLOAD_DEFAULT_MAX_SIZE = '10M';
const UPLOAD_DEFAULT_MIME_TYPE = 'application/pdf';
const MIME_TYPE_SPLIT_CAPABLE = 'application/pdf';
// $_FILES
const FILES_NAME = 'name';
const FILES_TMP_NAME = 'tmp_name';
const FILES_TYPE = 'type';
const FILES_ERROR = 'error';
const FILES_SIZE = 'size';
const FILES_FLAG_DELETE = 'flagDelete';
......
......@@ -70,7 +70,7 @@ class Delete {
// Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !chdir($sitePath)) {
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_SUPPORT => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR);
......@@ -91,7 +91,7 @@ class Delete {
}
chdir($cwd);
HelperFile::chdir($cwd);
}
/**
......@@ -124,11 +124,7 @@ class Delete {
// This check won't find duplicates, if they are spread over different columns or tables.
$samePathFileName = $this->db->sql("SELECT COUNT($primaryKey) AS cnt FROM $tableName WHERE $key LIKE ?", ROW_EXPECT_1, [$file]);
if ($samePathFileName['cnt'] === 1) {
if (!unlink($file)) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error deleting file', ERROR_MESSAGE_SUPPORT => "Error deleting file: $file"]),
ERROR_IO_UNLINK);
}
HelperFile::unlink($file);
}
}
}
......
......@@ -155,11 +155,7 @@ class File {
if (isset($statusUpload[FILES_TMP_NAME]) && $statusUpload[FILES_TMP_NAME] != '') {
$file = Support::extendFilename($statusUpload[FILES_TMP_NAME], UPLOAD_CACHED);
if (file_exists($file)) {
if (!unlink($file)) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Unlink file', ERROR_MESSAGE_SUPPORT => 'unlink file: ' . $file]),
ERROR_IO_UNLINK);
}
HelperFile::unlink($file);
}
$statusUpload[FILES_TMP_NAME] = '';
}
......
......@@ -766,7 +766,7 @@ class QuickFormQuery {
if (false !== ($arr = stat($file))) {
if (time() - $arr['mtime'] > FORM_LOG_FILE_EXPIRE) {
unlink($file);
HelperFile::unlink($file);
} else {
$form[FORM_LOG_FILE . '_' . $mode] = $file;
$form[FORM_LOG_ACTIVE] = 1;
......
......@@ -472,7 +472,7 @@ class Save {
// Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !chdir($sitePath)) {
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_SUPPORT => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR);
......@@ -520,11 +520,7 @@ class Save {
if (!file_exists($pathFileName . $extSave) &&
!file_exists($pathParts['dirname'] . $pathParts['filename'] . $extSave)
) {
if (!rename($pathFileName, $pathFileName . $extSave)) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Rename file', ERROR_MESSAGE_SUPPORT => "Rename file: '$pathFileName' > '$pathFileName$extSave'"]),
ERROR_IO_RENAME);
}
HelperFile::rename($pathFileName, $pathFileName . $extSave);
}
}
......@@ -581,7 +577,7 @@ class Save {
// Upload - Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !chdir($sitePath)) {
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_SUPPORT => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR);
......@@ -592,11 +588,7 @@ class Save {
$arr = $sip->getVarsFromSip($sipUpload);
$oldFile = $arr[EXISTING_PATH_FILE_NAME];
if (file_exists($oldFile)) {
if (!unlink($oldFile)) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Unlink file failed', ERROR_MESSAGE_SUPPORT => 'Unlink file failed: ' . $oldFile]),
ERROR_IO_UNLINK);
}
HelperFile::unlink($oldFile);
}
$flagDelete = ($oldFile != '');
}
......@@ -613,7 +605,7 @@ class Save {
$pathFileName = $this->copyUploadFile($formElement, $statusUpload);
}
chdir($cwd);
HelperFile::chdir($cwd);
// Delete current used uniq SIP
$this->store->setVar($sipUpload, array(), STORE_EXTRA);
......@@ -803,9 +795,9 @@ class Save {
}
$this->autoOrient($formElement, $pathFileName);
HelperFile::doChmod($pathFileName, $chmodFile);
HelperFile::chmod($pathFileName, $chmodFile);
$this->splitUpload($formElement, $pathFileName, $chmodFile);
$this->splitUpload($formElement, $pathFileName, $chmodFile, $statusUpload);
return $pathFileName;
}
......@@ -856,48 +848,30 @@ class Save {
* @param array $formElement
* @param string $pathFileName
* @param int $chmod
* @param array $statusUpload
* @throws CodeException
* @throws DbException
* @throws UserFormException
* @throws UserReportException
*/
private function splitUpload(array $formElement, $pathFileName, $chmod) {
private function splitUpload(array $formElement, $pathFileName, $chmod, array $statusUpload) {
if (empty($formElement[FE_FILE_SPLIT]) || empty($formElement[FE_FILE_DESTINATION_SPLIT])) {
if (empty($formElement[FE_FILE_SPLIT]) || $statusUpload[FILES_TYPE] != MIME_TYPE_SPLIT_CAPABLE) {
return;
}
$fileDestinationSplit = $this->evaluate->parse($formElement[FE_FILE_DESTINATION_SPLIT]);
$fileSplit = $this->evaluate->parse($formElement[FE_FILE_SPLIT]);
$fileSplitType = $this->evaluate->parse($formElement[FE_FILE_SPLIT]);
$fileSplitTableName = $this->evaluate->parse($formElement[FE_FILE_SPLIT_TABLE_NAME]);
if (empty($fileSplitTableName)) {
$fileSplitTableName = $this->formSpec[F_TABLE_NAME];
}
// Filetype testen: nur Dateien splitten die man auch wirklich entpacken kann
switch ($fileSplit) {
case FE_FILE_SPLIT_SVG:
$this->splitSvg($pathFileName, $fileDestinationSplit, $fileSplitTableName, $chmod);
break;
default:
throw new UserFormException("Unknown 'fileSplit' type: " . $formElement[FE_FILE_SPLIT], ERROR_UNKNOWN_TOKEN);
if ($fileDestinationSplit == '') {
$ext = ($fileSplitType == FE_FILE_SPLIT_SVG) ? '.%02d.svg' : '.jpg';
$fileDestinationSplit = $pathFileName . '.split/split' . $ext;
}
}
/**
* Split's the PDF file $pathFileNameSrc in several SVG-file, one per page.
* For every created file, a record in table 'Split' is created, storing the pathFileName to the individual file.
*
* @param string $pathFileNameSrc
* @param string $fileDestinationSplit
* @param string $fileSplitTableName
* @param int $chmod
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
private function splitSvg($pathFileNameSrc, $fileDestinationSplit, $fileSplitTableName, $chmod) {
Support::mkDirParent($fileDestinationSplit);
......@@ -907,15 +881,9 @@ class Save {
// Create temporary directory
$tempDir = Support::createTempDir();
$newSrc = $tempDir . DIRECTORY_SEPARATOR . QFQ_TEMP_SOURCE;
if (false === copy($pathFileNameSrc, $newSrc)) {
$msg = HelperFile::getLastErrorAsString() . " - copy $pathFileNameSrc $newSrc";
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'copy failed', ERROR_MESSAGE_SUPPORT => $msg]), ERROR_IO_COPY);
}
HelperFile::copy($pathFileName, $newSrc);
if (false === chdir($tempDir)) {
$msg = HelperFile::getLastErrorAsString() . " - chdir($tempDir)";
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'chdir failed', ERROR_MESSAGE_SUPPORT => $msg]), ERROR_IO_CHDIR);
}
HelperFile::chdir($tempDir);
// Split destination.
$pathParts = pathinfo($fileDestinationSplit);
......@@ -926,21 +894,42 @@ class Save {
// Extract filename from destination directory.
$fileNameDest = $pathParts['basename'];
switch ($fileSplitType) {
case FE_FILE_SPLIT_SVG:
$cmd = 'pdf2svg "' . $newSrc . '" "' . $fileNameDest . '" all';
break;
case FE_FILE_SPLIT_JPEG:
$cmd = 'convert -quality 90 -density 150 "' . $newSrc . '" "' . $fileNameDest . '"';
break;
default:
throw new UserFormException("Unknown 'fileSplit' type: " . $formElement[FE_FILE_SPLIT], ERROR_UNKNOWN_TOKEN);
}
// Split PDF
$cmd = 'pdf2svg "' . $newSrc . '" "' . $fileNameDest . '" all';
$output = Support::qfqExec($cmd, $rc);
if ($rc != 0) {
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'pdf2svg failed', ERROR_MESSAGE_SUPPORT => "[$cwd][cmd=$cmd]$output"]),
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'pdf2svg failed', ERROR_MESSAGE_SUPPORT => "[$cwd][cmd=$cmd]$output"]),
ERROR_PDF2SVG);
}
// Array of created filenames.
$files = scandir('.');
// Array of created file names.
if (false === ($files = scandir('.'))) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Splitted files not found', ERROR_MESSAGE_SUPPORT => "[cwd=$cwd] scandir(.)" . HelperFile::errorGetLastAsString()]),
ERROR_PDF2JPEG);
}
// IM 'convert' will produce files <file>-1.jpg <file>-10.jpg ... - bring them in natural sort order
natsort($files);
// Create DB records according to the extracted filenames.
$tableName = TABLE_NAME_SPLIT;
$sql = "INSERT INTO $tableName (`tableName`, `xId`, `pathFilename`, `created`) VALUES (?,?,?, NOW())";
$sql = "INSERT INTO $tableName (`tableName`, `xId`, `pathFilename`) VALUES (?,?,?)";
$xId = $this->store->getVar(COLUMN_ID, STORE_RECORD);
// 1) Move split files to final location. 2) Created records to reference each split file.
foreach ($files as $file) {
if ($file == '.' || $file == '..' || $file == QFQ_TEMP_SOURCE) {
......@@ -953,20 +942,21 @@ class Save {
$fileDestination = $file;
}
$rc = rename($file, Support::joinPath($cwd, $fileDestination));
HelperFile::doChmod($fileDestination, $chmod);
Support::moveFile($file, Support::joinPath($cwd, $fileDestination), true);
HelperFile::chmod($fileDestination, $chmod);
// Insert records.
$this->db->sql($sql, ROW_REGULAR, [$fileSplitTableName, $this->store->getVar(COLUMN_ID, STORE_RECORD), $fileDestination]);
$this->db->sql($sql, ROW_REGULAR, [$fileSplitTableName, $xId, $fileDestination]);
}
// Pop directory
$rc = chdir($cwd);
HelperFile::chdir($cwd);
// Remove duplicated source
$rc = unlink($newSrc);
HelperFile::unlink($newSrc);
// Remove empty directory
$rc = rmdir($tempDir);
HelperFile::rmdir($tempDir);
}
/**
......
......@@ -590,11 +590,7 @@ class FormAction {
}
Support::mkDirParent($rowDest[$key]);
if (!copy($val, $rowDest[$key])) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error copy file', ERROR_MESSAGE_SUPPORT => "Error copy file from [$val] to [" . $rowDest[$key] . "]"]),
ERROR_IO_COPY_FILE);
}
HelperFile::copy($val, $rowDest[$key]);
}
}
......
......@@ -20,17 +20,18 @@ class HelperFile {
* Iterate over array $files. Delete only named files which are stored in '/tmp/' . DOWNLOAD_FILE_PREFIX.
*
* @param array $files
* @throws UserFormException
*/
public static function cleanTempFiles(array $files) {
foreach ($files as $file) {
if (self::isQfqTemp($file)) {
unlink($file);
self::unlink($file);
}
$dir = dirname($file);
if (self::isQfqTemp($dir)) {
rmdir($dir);
self::rmdir($dir);
}
}
}
......@@ -60,10 +61,11 @@ class HelperFile {
/**
* Creates a temporary directory.
* @throws UserFormException
*/
public static function mktempdir() {
$name = tempnam(sys_get_temp_dir(), TMP_FILE_PREFIX);
unlink($name);
self::unlink($name);
mkdir($name);
return $name;
......@@ -224,25 +226,24 @@ class HelperFile {
/**
* @param $pathFileName
* @param bool $chmod
* @param int|bool $mode
* @throws UserFormException
*/
public static function doChmod($pathFileName, $chmod = false) {
public static function chmod($pathFileName, $mode = false) {
if ($chmod !== false) {
if (false === chmod($pathFileName, $chmod)) {
if ($mode !== false) {
if (false === chmod($pathFileName, $mode)) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Failed: chmod', ERROR_MESSAGE_SUPPORT => "Failed: chmod $chmod '$pathFileName'"]),
json_encode([ERROR_MESSAGE_TO_USER => 'Failed: chmod', ERROR_MESSAGE_SUPPORT => "Failed: chmod $mode '$pathFileName'"]),
ERROR_IO_CHMOD);
}
}
}
/**
* @return string
*/
public static function getLastErrorAsString() {
public static function errorGetLastAsString() {
if (NULL === ($errors = error_get_last())) {
return '';
......@@ -251,4 +252,91 @@ class HelperFile {
return $errors['type'] . ' - ' . $errors['message'];
}
/**
* PHP System function: chdir() with QFQ exception
*
* @param $cwd
* @return string
* @throws UserFormException
*/
public static function chdir($cwd) {
if (false === chdir($cwd)) {
$msg = self::errorGetLastAsString() . " - chdir($cwd)";
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'chdir failed', ERROR_MESSAGE_SUPPORT => $msg]), ERROR_IO_CHDIR);
}
return true;
}
/**
* PHP System function: unlink() with QFQ exception
*
* @param $newSrc
* @return string
* @throws UserFormException
*/
public static function unlink($newSrc) {
if (false === unlink($newSrc)) {
$msg = self::errorGetLastAsString() . " - unlink($newSrc)";
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'unlink failed', ERROR_MESSAGE_SUPPORT => $msg]), ERROR_IO_UNLINK);
}
return true;
}
/**
* PHP System function: rmdir() with QFQ exception
*
* @param $tempDir
* @return string
* @throws UserFormException
*/
public static function rmdir($tempDir) {
if (false === rmdir($tempDir)) {
$msg = self::errorGetLastAsString() . " - rmdir($tempDir)";
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'unlink failed', ERROR_MESSAGE_SUPPORT => $msg]), ERROR_IO_RMDIR);
}
return true;
}
/**
* PHP System function: rename() with QFQ exception
*
* @param $oldname
* @param $newname
* @return string
* @throws UserFormException
*/
public static function rename($oldname, $newname) {
if (false === rename($oldname, $newname)) {
$msg = self::errorGetLastAsString() . " - rename($oldname ,$newname)";
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'unlink failed', ERROR_MESSAGE_SUPPORT => $msg]), ERROR_IO_RMDIR);
}
return true;
}
/**
* PHP System function: copy() with QFQ exception
*
* @param $source
* @param $dest
* @return string
* @throws UserFormException
*/
public static function copy($source, $dest) {
if (false === copy($source, $dest)) {
$msg = self::errorGetLastAsString() . " - copy($source, $dest)";
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'unlink failed', ERROR_MESSAGE_SUPPORT => $msg]), ERROR_IO_RMDIR);
}
return true;
}
}
\ No newline at end of file
......@@ -45,7 +45,7 @@ class Logger {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error: cannot open file',
ERROR_MESSAGE_SUPPORT => "Error - cannot open. File: " . $filename .
" ( CWD: " . getcwd() . ") - " . HelperFile::getLastErrorAsString()]),
" ( CWD: " . getcwd() . ") - " . HelperFile::errorGetLastAsString()]),
ERROR_IO_OPEN);
}
}
......@@ -54,7 +54,7 @@ class Logger {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error: cannot write file',
ERROR_MESSAGE_SUPPORT => "Error - cannot open. File: " . $filename .
" ( CWD: " . getcwd() . ") - " . HelperFile::getLastErrorAsString()]),
" ( CWD: " . getcwd() . ") - " . HelperFile::errorGetLastAsString()]),
ERROR_IO_WRITE);
}
......
......@@ -57,12 +57,13 @@ class SessionCookie {
/**
* Unlink current cookie file
* @throws UserFormException
*/
public function __destruct() {
if ($this->cleanTempFiles) {
if (file_exists($this->pathFileNameCookie)) {
unlink($this->pathFileNameCookie);
HelperFile::unlink($this->pathFileNameCookie);
$this->pathFileNameCookie = '';
}
}
......
......@@ -1268,7 +1268,7 @@ class Support {
}
} else {
mkdir($path);
HelperFile::doChmod($path, $chmodDir);
HelperFile::chmod($path, $chmodDir);
}
}
$path .= "/";
......@@ -1286,9 +1286,7 @@ class Support {
if (file_exists($pathFileName)) {
if ($overwrite) {
if (!unlink($pathFileName)) {
throw new UserFormException('Copy upload failed - file exist and unlink() failed: ' . $pathFileName, ERROR_IO_UNLINK);
}
HelperFile::unlink($pathFileName);
} else {
throw new UserFormException('Copy upload failed - file already exist: ' . $pathFileName, ERROR_IO_FILE_EXIST);
}
......@@ -1297,14 +1295,9 @@ class Support {
Support::mkDirParent($pathFileName, $chmodDir);
// Do not use 'rename' - might cause trouble if src and dest are on different filesystems.
if (!copy($srcFile, $pathFileName)) {
throw new UserFormException("Copy file: '$srcFile' > '$pathFileName'", ERROR_IO_COPY);
}
if (!unlink($srcFile)) {
throw new UserFormException("Delete temporary uploaded file: '$srcFile'", ERROR_IO_UNLINK);
}
HelperFile::copy($srcFile, $pathFileName);
HelperFile::unlink($srcFile);
}
/**