diff --git a/htdocs/adherents/document.php b/htdocs/adherents/document.php
index 2fb69913ace..37bdd7c150b 100644
--- a/htdocs/adherents/document.php
+++ b/htdocs/adherents/document.php
@@ -72,39 +72,7 @@ if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
// Suppression fichier
diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php
index 06438f3ef90..75bf3c41e76 100644
--- a/htdocs/admin/mails.php
+++ b/htdocs/admin/mails.php
@@ -83,40 +83,7 @@ if (GETPOST('addfile') || GETPOST('addfilehtml'))
// Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp';
-
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'], 1, 0, $_FILES['addedfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- setEventMessage($langs->trans("FileTransferComplete"));
-
- include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
- $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
- else
- {
- $langs->load("errors");
- $mesg = '
'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'
';
- }
+ dol_add_file_process($upload_dir,0,0);
if ($_POST['addfile']) $action='test';
if ($_POST['addfilehtml']) $action='testhtml';
diff --git a/htdocs/admin/security_other.php b/htdocs/admin/security_other.php
index 0ff71e128c0..900cbe42340 100644
--- a/htdocs/admin/security_other.php
+++ b/htdocs/admin/security_other.php
@@ -39,42 +39,11 @@ $upload_dir=$conf->admin->dir_temp;
* Actions
*/
-if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
+if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
- $result=dol_mkdir($upload_dir); // Create dir if not exists
- if ($result >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1,0,$_FILES['userfile']['error']);
-
- if (is_numeric($resupload) && $resupload > 0)
- {
- setEventMessage($langs->trans("FileTransferComplete"));
-
- include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
- $formmail = new FormMail($db);
- $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus.(.*)/',$resupload,$reg)) // Files infected by a virus
- {
- $mesg = ''.$langs->trans("ErrorFileIsInfectedWithAVirus");
- $mesg.= '
'.$langs->trans("Information").': '.$langs->trans($reg[1]);
- $mesg.= '
';
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,0);
}
if ($_GET["action"] == 'activate_captcha')
diff --git a/htdocs/comm/action/document.php b/htdocs/comm/action/document.php
index 38728043e6c..34ad7b13af5 100755
--- a/htdocs/comm/action/document.php
+++ b/htdocs/comm/action/document.php
@@ -68,42 +68,8 @@ if (! $sortfield) $sortfield="name";
*/
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- // Creation repertoire si n'existe pas
$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid);
-
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
/*
diff --git a/htdocs/comm/propal/document.php b/htdocs/comm/propal/document.php
index 9b6b6bff336..5529f2c9b9c 100644
--- a/htdocs/comm/propal/document.php
+++ b/htdocs/comm/propal/document.php
@@ -75,43 +75,8 @@ if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
if ($object->id > 0)
{
- $object->fetch_thirdparty();
-
$upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref);
-
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
}
diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php
index 0bccb1286b9..c01b8a98b5a 100644
--- a/htdocs/commande/document.php
+++ b/htdocs/commande/document.php
@@ -72,42 +72,8 @@ if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
if ($object->fetch($id))
{
$object->fetch_thirdparty();
-
$upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref);
-
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
}
diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php
index 52293e71ccf..05750bb2238 100644
--- a/htdocs/compta/facture/document.php
+++ b/htdocs/compta/facture/document.php
@@ -75,42 +75,8 @@ if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
if ($object->fetch($id))
{
$object->fetch_thirdparty();
-
$upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
-
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
}
diff --git a/htdocs/compta/sociales/document.php b/htdocs/compta/sociales/document.php
index 937bb51bb31..860584234bc 100644
--- a/htdocs/compta/sociales/document.php
+++ b/htdocs/compta/sociales/document.php
@@ -73,39 +73,15 @@ $modulepart='tax';
if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
+}
+
+if ($action == 'delete')
+{
+ $file = $upload_dir . '/' . GETPOST("urlfile"); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
+ $ret=dol_delete_file($file);
+ if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
+ else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
}
@@ -120,14 +96,6 @@ llxHeader("",$langs->trans("SocialContribution"),$help_url);
if ($object->id)
{
- if ($action == 'delete')
- {
- $file = $upload_dir . '/' . GETPOST("urlfile"); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
- $ret=dol_delete_file($file);
- if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
- else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
- }
-
$head=tax_prepare_head($object, $user);
dol_fiche_head($head, 'documents', $langs->trans("SocialContribution"), 0, 'bill');
diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php
index d9a26cc6222..7474a098f34 100644
--- a/htdocs/contrat/document.php
+++ b/htdocs/contrat/document.php
@@ -78,39 +78,7 @@ $modulepart='contract';
*/
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
// Delete
diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php
index ef52e32d72f..f4e19d333d2 100644
--- a/htdocs/core/lib/files.lib.php
+++ b/htdocs/core/lib/files.lib.php
@@ -927,27 +927,37 @@ function dol_init_file_process($pathtoscan='')
* @param string $upload_dir Directory to store upload files
* @param int $allowoverwrite 1=Allow overwrite existing file
* @param int $donotupdatesession 1=Do no edit _SESSION variable
+ * @param string $varfiles _FILES var name
* @return void
*/
-function dol_add_file_process($upload_dir,$allowoverwrite=0,$donotupdatesession=0)
+function dol_add_file_process($upload_dir,$allowoverwrite=0,$donotupdatesession=0,$varfiles='addedfile')
{
global $db,$user,$conf,$langs,$_FILES;
- if (! empty($_FILES['addedfile']['tmp_name']))
+ if (! empty($_FILES[$varfiles]['tmp_name']))
{
if (dol_mkdir($upload_dir) >= 0)
{
- $resupload = dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],$allowoverwrite,0, $_FILES['addedfile']['error']);
+ $resupload = dol_move_uploaded_file($_FILES[$varfiles]['tmp_name'], $upload_dir . "/" . $_FILES[$varfiles]['name'],$allowoverwrite,0, $_FILES[$varfiles]['error']);
if (is_numeric($resupload) && $resupload > 0)
{
- setEventMessage($langs->trans("FileTransferComplete"));
-
if (empty($donotupdatesession))
{
include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
$formmail = new FormMail($db);
- $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
+ $formmail->add_attached_files($upload_dir . "/" . $_FILES[$varfiles]['name'],$_FILES[$varfiles]['name'],$_FILES[$varfiles]['type']);
}
+ else if (image_format_supported($upload_dir . "/" . $_FILES[$varfiles]['name']) == 1)
+ {
+ // Create small thumbs for image (Ratio is near 16/9)
+ // Used on logon for example
+ $imgThumbSmall = vignette($upload_dir . "/" . $_FILES[$varfiles]['name'], 160, 120, '_small', 50, "thumbs");
+ // Create mini thumbs for image (Ratio is near 16/9)
+ // Used on menu or for setup page for example
+ $imgThumbMini = vignette($upload_dir . "/" . $_FILES[$varfiles]['name'], 160, 120, '_mini', 50, "thumbs");
+ }
+
+ setEventMessage($langs->trans("FileTransferComplete"));
}
else
{
@@ -1006,10 +1016,10 @@ function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=
else $result=0;
if ($result >= 0)
{
- if (empty($donotdeletefile))
- {
+ if (empty($donotdeletefile))
+ {
$langs->load("other");
- setEventMessage($langs->trans("FileWasRemoved",$filetodelete));
+ setEventMessage($langs->trans("FileWasRemoved",$filetodelete));
}
if (empty($donotupdatesession))
{
diff --git a/htdocs/fichinter/document.php b/htdocs/fichinter/document.php
index 3380984c17b..06309ce89e3 100644
--- a/htdocs/fichinter/document.php
+++ b/htdocs/fichinter/document.php
@@ -75,40 +75,7 @@ if (GETPOST('sendit','alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for company (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
-
- // Create mini thumbs for company (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
// Delete
diff --git a/htdocs/fourn/commande/document.php b/htdocs/fourn/commande/document.php
index b8c35d1fda3..a28889d97f9 100644
--- a/htdocs/fourn/commande/document.php
+++ b/htdocs/fourn/commande/document.php
@@ -79,39 +79,7 @@ $object->fetch_thirdparty();
// Envoi fichier
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
else if ($action == 'confirm_deletefile' && $confirm == 'yes')
diff --git a/htdocs/fourn/facture/document.php b/htdocs/fourn/facture/document.php
index a494f6aea8c..ccfa1a8b24e 100644
--- a/htdocs/fourn/facture/document.php
+++ b/htdocs/fourn/facture/document.php
@@ -64,7 +64,7 @@ $object = new FactureFournisseur($db);
*/
// Envoi fichier
-if ($_POST['sendit'] && ! empty($conf->global->MAIN_UPLOAD_DOC))
+if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
@@ -73,40 +73,7 @@ if ($_POST['sendit'] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
$ref=dol_sanitizeFileName($facture->ref);
$upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($facture->id,2).$ref;
-
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
}
diff --git a/htdocs/product/document.php b/htdocs/product/document.php
index 502a4a54f1f..47f985bff2f 100755
--- a/htdocs/product/document.php
+++ b/htdocs/product/document.php
@@ -74,39 +74,7 @@ $modulepart='produit';
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
// Delete
diff --git a/htdocs/projet/document.php b/htdocs/projet/document.php
index a651796bc6f..83aaabc58f5 100644
--- a/htdocs/projet/document.php
+++ b/htdocs/projet/document.php
@@ -69,43 +69,10 @@ if (! $sortfield) $sortfield="name";
*/
// Envoi fichier
-if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
+if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
$upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
-
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
// Delete
diff --git a/htdocs/projet/tasks/document.php b/htdocs/projet/tasks/document.php
index f8e58ff4fe3..a60fab5b03a 100644
--- a/htdocs/projet/tasks/document.php
+++ b/htdocs/projet/tasks/document.php
@@ -69,41 +69,9 @@ $projectstatic = new Project($db);
*/
// Envoi fichier
-if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
+if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if ($resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
// Delete
diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php
index dfe8dd9ddb3..fc1c2cb45c2 100644
--- a/htdocs/societe/document.php
+++ b/htdocs/societe/document.php
@@ -76,43 +76,11 @@ if ($id > 0 || ! empty($ref))
// TODO Use an include to mutualize this code for action sendit and confirm_deletefile
// Post file
-if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
+if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
if ($object->id)
{
- if (dol_mkdir($upload_dir) >= 0)
- {
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
- {
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for image (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
- // Create mini thumbs for image (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- setEventMessage($langs->trans("FileTransferComplete"));
- }
- else
- {
- $langs->load("errors");
- if (is_numeric($resupload) && $resupload < 0) // Unknown error
- {
- setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
- }
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
- {
- setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
- }
- else // Known error
- {
- setEventMessage($langs->trans($resupload), 'errors');
- }
- }
- }
+ dol_add_file_process($upload_dir,0,1,'userfile');
}
}