FIX Can overwrite file if exists in file manager
This commit is contained in:
parent
024abe8b58
commit
965bdf733d
@ -52,15 +52,16 @@ if (GETPOST('sendit', 'alpha') && !empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
{
|
||||
// Define if we have to generate thumbs or not
|
||||
$generatethumbs = 1;
|
||||
if (GETPOST('section_dir')) $generatethumbs = 0;
|
||||
if (GETPOST('section_dir', 'alpha')) $generatethumbs = 0;
|
||||
$allowoverwrite = (GETPOST('overwritefile', 'int') ? 1 : 0);
|
||||
|
||||
if (!empty($upload_dirold) && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
|
||||
{
|
||||
$result = dol_add_file_process($upload_dirold, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs);
|
||||
$result = dol_add_file_process($upload_dirold, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs);
|
||||
}
|
||||
elseif (!empty($upload_dir))
|
||||
{
|
||||
$result = dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs);
|
||||
$result = dol_add_file_process($upload_dir, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ class FormFile
|
||||
* @param integer $linkfiles 1=Also add form to link files, 0=Do not show form to link files
|
||||
* @param string $htmlname Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM)
|
||||
* @param string $accept Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*')
|
||||
* @param string $sectiondir If upload must be done inside a particular directory (is sectiondir defined, sectionid must not be)
|
||||
* @param string $sectiondir If upload must be done inside a particular directory (if sectiondir defined, sectionid must not be)
|
||||
* @param int $usewithoutform 0=Default, 1=Disable <form> and style to use in existing area
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
@ -108,8 +108,6 @@ class FormFile
|
||||
return 1;
|
||||
}
|
||||
|
||||
$maxlength = $size;
|
||||
|
||||
$out = "\n\n".'<!-- Start form attach new file --><div class="formattachnewfile">'."\n";
|
||||
|
||||
if (empty($title)) $title = $langs->trans("AttachANewFile");
|
||||
@ -174,6 +172,10 @@ class FormFile
|
||||
$out .= (!empty($accept) ? ' accept="'.$accept.'"' : ' accept=""');
|
||||
$out .= '>';
|
||||
$out .= ' ';
|
||||
if ($sectionid) { // Show overwrite if exists for ECM module only
|
||||
$langs->load('link');
|
||||
$out .= '<input style="margin-right: 2px;" type="checkbox" id="overwritefile" name="overwritefile" value="1"><label for="overwritefile">'.$langs->trans("OverwriteIfExists").'</label>';
|
||||
}
|
||||
$out .= '<input type="submit" class="button reposition" name="sendit" value="'.$langs->trans("Upload").'"';
|
||||
$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm) ? ' disabled' : '');
|
||||
$out .= '>';
|
||||
|
||||
@ -1598,13 +1598,18 @@ function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesess
|
||||
$formmail->add_attached_files($destfull, $destfile, $TFile['type'][$i]);
|
||||
}
|
||||
|
||||
// Update table of files
|
||||
// Update index table of files (llx_ecm_files)
|
||||
if ($donotupdatesession == 1)
|
||||
{
|
||||
$result = addFileIntoDatabaseIndex($upload_dir, basename($destfile), $TFile['name'][$i], 'uploaded', 0);
|
||||
if ($result < 0)
|
||||
{
|
||||
setEventMessages('FailedToAddFileIntoDatabaseIndex', '', 'warnings');
|
||||
if ($allowoverwrite) {
|
||||
// Do not show error message. We can have an error due to DB_ERROR_RECORD_ALREADY_EXISTS
|
||||
}
|
||||
else {
|
||||
setEventMessages('FailedToAddFileIntoDatabaseIndex', '', 'warnings');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1760,7 +1765,6 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete files into database index using search criterias.
|
||||
*
|
||||
|
||||
@ -8,3 +8,4 @@ LinkRemoved=The link %s has been removed
|
||||
ErrorFailedToDeleteLink= Failed to remove link '<b>%s</b>'
|
||||
ErrorFailedToUpdateLink= Failed to update link '<b>%s</b>'
|
||||
URLToLink=URL to link
|
||||
OverwriteIfExists=Overwrite file if exists
|
||||
|
||||
Loading…
Reference in New Issue
Block a user