Fix: Better error management in upload files

This commit is contained in:
Laurent Destailleur 2010-05-01 14:28:48 +00:00
parent 9e887c8980
commit 968addfad3
36 changed files with 739 additions and 591 deletions

View File

@ -212,6 +212,8 @@ if ($_REQUEST["action"] == 'confirm_sendinfo' && $_REQUEST["confirm"] == 'yes')
if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer) if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$datenaiss=''; $datenaiss='';
if (isset($_POST["naissday"]) && $_POST["naissday"] if (isset($_POST["naissday"]) && $_POST["naissday"]
&& isset($_POST["naissmonth"]) && $_POST["naissmonth"] && isset($_POST["naissmonth"]) && $_POST["naissmonth"]
@ -293,7 +295,7 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adhe
if (@is_dir($dir)) if (@is_dir($dir))
{ {
$newfile=$dir.'/'.$_FILES['photo']['name']; $newfile=$dir.'/'.$_FILES['photo']['name'];
if (! dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1) > 0) if (! dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1,0,$_FILES['photo']['error']) > 0)
{ {
$message .= '<div class="error">'.$langs->trans("ErrorFailedToSaveFile").'</div>'; $message .= '<div class="error">'.$langs->trans("ErrorFailedToSaveFile").'</div>';
} }

View File

@ -51,6 +51,8 @@ $quality = 80;
if ( (isset($_POST["action"]) && $_POST["action"] == 'update') if ( (isset($_POST["action"]) && $_POST["action"] == 'update')
|| (isset($_POST["action"]) && $_POST["action"] == 'updateedit') ) || (isset($_POST["action"]) && $_POST["action"] == 'updateedit') )
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM",$_POST["nom"],'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM",$_POST["nom"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ADRESSE",$_POST["address"],'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ADRESSE",$_POST["address"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_VILLE",$_POST["ville"],'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_VILLE",$_POST["ville"],'chaine',0,'',$conf->entity);
@ -77,7 +79,7 @@ if ( (isset($_POST["action"]) && $_POST["action"] == 'update')
{ {
create_exdir($conf->mycompany->dir_output.'/logos/'); create_exdir($conf->mycompany->dir_output.'/logos/');
} }
if (dol_move_uploaded_file($_FILES["logo"]["tmp_name"],$conf->mycompany->dir_output.'/logos/'.$original_file,1) > 0) if (dol_move_uploaded_file($_FILES["logo"]["tmp_name"],$conf->mycompany->dir_output.'/logos/'.$original_file,1,0,$_FILES['logo']['error']) > 0)
{ {
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO",$original_file,'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO",$original_file,'chaine',0,'',$conf->entity);

View File

@ -68,40 +68,46 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update')
*/ */
if ($_POST['addfile'] || $_POST['addfilehtml']) if ($_POST['addfile'] || $_POST['addfilehtml'])
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
// Set tmp user directory // Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id; $vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/'; $upload_dir = $vardir.'/temp/';
if (! empty($_FILES['addedfile']['tmp_name'])) if (create_exdir($upload_dir) >= 0)
{ {
if (! is_dir($upload_dir)) create_exdir($upload_dir); $resupload=dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0,0,$_FILES['addedfile']['error']);
if (is_numeric($resupload) && $resupload > 0)
if (is_dir($upload_dir))
{ {
$result = dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0); $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
if ($result > 0)
{
$message = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php'); include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php');
$formmail = new FormMail($db); $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['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
} }
else if ($result == -99) else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{ {
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>'; $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
} }
else if ($result < 0) else // Known error
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
// print_r($_FILES);
} }
} }
} }
else
{
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'</div>';
}
if ($_POST['addfile']) $_GET["action"]='test'; if ($_POST['addfile']) $_GET["action"]='test';
if ($_POST['addfilehtml']) $_GET["action"]='testhtml'; if ($_POST['addfilehtml']) $_GET["action"]='testhtml';
} }

View File

@ -42,29 +42,37 @@ $upload_dir=$conf->admin->dir_temp;
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
$result=create_exdir($upload_dir); // Create dir if not exists require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$result=create_exdir($upload_dir); // Create dir if not exists
if ($result >= 0) if ($result >= 0)
{ {
$resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],1); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],1,0,$_FILES['userfile']['error']);
if (is_numeric($resupload) && $resupload > 0)
{ if (is_numeric($resupload) && $resupload > 0)
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; {
//print_r($_FILES); $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
}
else if (is_numeric($resupload) && $resupload == -99) include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php');
{ $formmail = new FormMail($db);
// File infected by a virus $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
$langs->load("errors"); }
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>'; else
} {
else $langs->load("errors");
{ if ($resupload < 0) // Unknown error
// Echec transfert (fichier depassant la limite ?) {
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded"); $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
if (is_array($resupload)) $mesg.= '<br>'.dol_nl2br(join("\n",$resupload)); }
$mesg.= '</div>'; else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
// print_r($_FILES); {
} $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
} }
} }
@ -261,8 +269,20 @@ print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
print '<td colspan="2">'.$langs->trans("AntiVirusCommand").'<br>'; print '<td colspan="2">'.$langs->trans("AntiVirusCommand").'<br>';
print $langs->trans("AntiVirusCommandExample"); print $langs->trans("AntiVirusCommandExample");
// Check command in inside safe_mode
print '</td>'; print '</td>';
print '<td align="center" width="100">'; print '<td align="center" width="100">';
if (ini_get('safe_mode') && ! empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
{
$langs->load("errors");
$basedir=preg_replace('/"/','',dirname($conf->global->MAIN_ANTIVIRUS_COMMAND));
$listdir=explode(';',ini_get('safe_mode_exec_dir'));
if (! in_array($basedir,$listdir))
{
print img_warning($langs->trans('WarningSafeModeOnCheckExecDir'));
dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING);
}
}
print '<input type="text" name="MAIN_ANTIVIRUS_COMMAND" size=80 value="'.htmlentities($conf->global->MAIN_ANTIVIRUS_COMMAND).'">'; print '<input type="text" name="MAIN_ANTIVIRUS_COMMAND" size=80 value="'.htmlentities($conf->global->MAIN_ANTIVIRUS_COMMAND).'">';
print "</td>"; print "</td>";
print '<td align="right">'; print '<td align="right">';

View File

@ -1018,6 +1018,8 @@ class Categorie
*/ */
function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120) function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120)
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$dir = $sdir .'/'. get_exdir($this->id,2) . $this->id ."/"; $dir = $sdir .'/'. get_exdir($this->id,2) . $this->id ."/";
$dir .= "photos/"; $dir .= "photos/";
@ -1031,7 +1033,7 @@ class Categorie
$originImage = $dir . $file['name']; $originImage = $dir . $file['name'];
// Cree fichier en taille origine // Cree fichier en taille origine
$result=dol_move_uploaded_file($file['tmp_name'], $originImage, 1); $result=dol_move_uploaded_file($file['tmp_name'], $originImage, 1, 0, 0);
if (file_exists($originImage)) if (file_exists($originImage))
{ {

View File

@ -69,31 +69,33 @@ $pagenext = $page + 1;
*/ */
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
/* require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
* Creation repertoire si n'existe pas
*/
$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid);
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir)) // Creation repertoire si n'existe pas
$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid);
if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
}
else if ($result == -99)
{
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; }
// print_r($_FILES); else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
} }

View File

@ -442,6 +442,8 @@ if (! empty($_POST["removedfile"]))
// Action update emailing // Action update emailing
if ($_POST["action"] == 'update' && empty($_POST["removedfile"]) && empty($_POST["cancel"])) if ($_POST["action"] == 'update' && empty($_POST["removedfile"]) && empty($_POST["cancel"]))
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$mil = new Mailing($db); $mil = new Mailing($db);
$mil->fetch($_POST["id"]); $mil->fetch($_POST["id"]);
@ -451,39 +453,37 @@ if ($_POST["action"] == 'update' && empty($_POST["removedfile"]) && empty($_POST
// If upload file // If upload file
$i=''; $i='';
//$i=0; if (! empty($_POST["addfile".$i]) && ! empty($conf->global->MAIN_UPLOAD_DOC))
//while ($i < 4) {
//{ $isupload=1;
if (! empty($_POST["addfile".$i]) && ! empty($conf->global->MAIN_UPLOAD_DOC))
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir))
{ {
$isupload=1; $resupload = dol_move_uploaded_file($_FILES['addedfile'.$i]['tmp_name'], $upload_dir . "/" . $_FILES['addedfile'.$i]['name'],1,0,$_FILES['addedfile'.$i]['error']);
if (is_numeric($resupload) && $resupload > 0)
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir))
{ {
$result = dol_move_uploaded_file($_FILES['addedfile'.$i]['tmp_name'], $upload_dir . "/" . $_FILES['addedfile'.$i]['name'],1); $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
if ($result > 0) }
{ else
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; {
//print_r($_FILES); $langs->load("errors");
} if ($resupload < 0) // Unknown error
else if ($result == -99)
{
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?)
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
// print_r($_FILES); }
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
} }
} }
} }
// $i++; }
//}
if (! $isupload) if (! $isupload)
{ {

View File

@ -381,38 +381,41 @@ if ($_REQUEST['action'] == 'setstatut' && $user->rights->propale->cloturer)
*/ */
if ($_POST['addfile']) if ($_POST['addfile'])
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
// Set tmp user directory // Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id; $vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/'; $upload_dir = $vardir.'/temp/';
if (! empty($_FILES['addedfile']['tmp_name'])) if (! empty($_FILES['addedfile']['tmp_name']))
{ {
if (! is_dir($upload_dir)) create_exdir($upload_dir); if (create_exdir($upload_dir) >= 0)
if (is_dir($upload_dir))
{ {
$result = dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0,0,$_FILES['addedfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{ {
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php'); include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php');
$formmail = new FormMail($db); $formmail = new FormMail($db);
// Add file in list of files in session // Add file in list of files in session
$formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']); $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
} }
else if ($result == -99) else
{ {
// Files infected by a virus
$langs->load("errors"); $langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>'; if ($resupload < 0) // Unknown error
} {
else if ($result < 0) $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
{ }
// Echec transfert (fichier depassant la limite ?) else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; {
// print_r($_FILES); $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
} }

View File

@ -68,34 +68,38 @@ $pagenext = $page + 1;
// Envoi fichier // Envoi fichier
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$propal = new Propal($db); $propal = new Propal($db);
if ($propal->fetch($propalid)) if ($propal->fetch($propalid))
{ {
$upload_dir = $conf->propale->dir_output . "/" . dol_sanitizeFileName($propal->ref); $upload_dir = $conf->propale->dir_output . "/" . dol_sanitizeFileName($propal->ref);
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{ {
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES); }
} else
else if ($result == -99) {
{ $langs->load("errors");
// Files infected by a virus if ($resupload < 0) // Unknown error
$langs->load("errors"); {
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>'; $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
} }
else if ($result < 0) else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; }
// print_r($_FILES); else // Known error
} {
} $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
}
} }
} }

View File

@ -76,28 +76,32 @@ if (! $commande->fetch($_GET['id'],$_GET['ref']) > 0)
// Envoi fichier // Envoi fichier
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
$upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($commande->ref); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir)) $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($commande->ref);
if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
}
else if ($result == -99)
{
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; }
// print_r($_FILES); else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
} }

View File

@ -774,40 +774,42 @@ if ($_REQUEST['action'] == 'remove_file')
*/ */
if ($_POST['addfile']) if ($_POST['addfile'])
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
// Set tmp user directory // Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id; $vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/'; $upload_dir = $vardir.'/temp/';
if (! empty($_FILES['addedfile']['tmp_name'])) if (create_exdir($upload_dir) >= 0)
{ {
if (! is_dir($upload_dir)) create_exdir($upload_dir); $resupload=dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0,0,$_FILES['addedfile']['error']);
if (is_numeric($resupload) && $resupload > 0)
if (is_dir($upload_dir))
{ {
$result = dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0); $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
if ($result > 0)
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php'); include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php');
$formmail = new FormMail($db); $formmail = new FormMail($db);
$formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']); // Add file in list of files in session
} $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
else if ($result == -99) }
else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{ {
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>'; $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
} }
else if ($result < 0) else // Known error
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
// print_r($_FILES);
} }
} }
} }
$_GET["action"]='presend'; $_GET["action"]='presend';
} }

View File

@ -1089,40 +1089,43 @@ if ($_GET['action'] == 'down' && $user->rights->facture->creer)
*/ */
if ($_POST['addfile']) if ($_POST['addfile'])
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
// Set tmp user directory // Set tmp user directory
$vardir=$conf->user->dir_output."/".$user->id; $vardir=$conf->user->dir_output."/".$user->id;
$upload_dir = $vardir.'/temp/'; $upload_dir = $vardir.'/temp/';
if (! empty($_FILES['addedfile']['tmp_name'])) if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir))
{ {
if (! is_dir($upload_dir)) create_exdir($upload_dir); $resupload = dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0,0, $_FILES['addedfile']['error']);
if (is_numeric($resupload) && $resupload > 0)
if (is_dir($upload_dir))
{ {
$result = dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0); $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
if ($result > 0)
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php'); include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php');
$formmail = new FormMail($db); $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['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
} }
else if ($result == -99) else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{ {
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>'; $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
} }
else if ($result < 0) else // Known error
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
// print_r($_FILES);
} }
} }
} }
$_GET["action"]='presend'; $_GET["action"]='presend';
} }

View File

@ -72,31 +72,35 @@ $pagenext = $page + 1;
// Envoi fichier // Envoi fichier
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$facture = new Facture($db); $facture = new Facture($db);
if ($facture->fetch($facid)) if ($facture->fetch($facid))
{ {
$upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($facture->ref); $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($facture->ref);
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{ {
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
} }
else if ($result == -99) else
{ {
// Files infected by a virus
$langs->load("errors"); $langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>'; if ($resupload < 0) // Unknown error
} {
else if ($result < 0) $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
{ }
// Echec transfert (fichier depassant la limite ?) else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; {
// print_r($_FILES); $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
} }

View File

@ -54,6 +54,8 @@ if ($_POST["action"] == 'confirm_credite' && $_POST["confirm"] == yes)
if ($_POST["action"] == 'infotrans') if ($_POST["action"] == 'infotrans')
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$bon = new BonPrelevement($db,""); $bon = new BonPrelevement($db,"");
$bon->fetch($_GET["id"]); $bon->fetch($_GET["id"]);

View File

@ -72,32 +72,32 @@ $modulepart='contract';
*/ */
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
/* require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
* Creation repertoire si n'existe pas
*/
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
}
else if ($result == -99)
{
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
// print_r($_FILES);
} }
} else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
}
} }

View File

@ -91,32 +91,30 @@ $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
// Envoie fichier // Envoie fichier
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
if (! is_dir($upload_dir)) require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
{
$result=create_exdir($upload_dir);
}
if (is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{ {
//$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
$result=$ecmdir->changeNbOfFiles('+'); $result=$ecmdir->changeNbOfFiles('+');
} }
else if ($result == -99) else
{ {
// File infected by a virus $langs->load("errors");
$langs->load("errors"); if ($resupload < 0) // Unknown error
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>'; {
} $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
else if ($result < 0) }
{ else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
// Echec transfert (fichier depassant la limite ?) {
$langs->load("errors"); $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; }
// print_r($_FILES); else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
else else

View File

@ -46,28 +46,37 @@ $upload_dir = $conf->ecm->dir_output.'/'.$section;
// Envoie fichier // Envoie fichier
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
if (! is_dir($upload_dir)) create_exdir($upload_dir); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
if (is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{ {
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; $result=$ecmdir->changeNbOfFiles('+');
//print_r($_FILES);
}
else if ($result == -99)
{
// File infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
} }
else if ($result < 0) else
{ {
// Echec transfert (fichier d?passant la limite ?) $langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; if ($resupload < 0) // Unknown error
// print_r($_FILES); {
} $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
}
else
{
// Echec transfert (fichier depassant la limite ?)
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'</div>';
} }
} }

View File

@ -87,6 +87,8 @@ if (! empty($_REQUEST["section"]))
// Envoie fichier // Envoie fichier
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$result=$ecmdir->fetch($_REQUEST["section"]); $result=$ecmdir->fetch($_REQUEST["section"]);
if (! $result > 0) if (! $result > 0)
{ {
@ -96,37 +98,34 @@ if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
$relativepath=$ecmdir->getRelativePath(); $relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath; $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
if (! is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result=create_exdir($upload_dir); $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0, 0, $_FILES['userfile']['error']);
} if (is_numeric($resupload) && $resupload > 0)
if (is_dir($upload_dir))
{
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0);
if ($result > 0)
{ {
//$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; //$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES); //print_r($_FILES);
$result=$ecmdir->changeNbOfFiles('+'); $result=$ecmdir->changeNbOfFiles('+');
} }
else if ($result == -99) else
{
// File infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?)
$langs->load("errors"); $langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; if ($resupload < 0) // Unknown error
// print_r($_FILES); {
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
else else
{ {
// Echec transfert (fichier depassant la limite ?)
$langs->load("errors"); $langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'</div>'; $mesg = '<div class="error">'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'</div>';
} }

View File

@ -69,32 +69,32 @@ $modulepart='fichinter';
*/ */
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
/* require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
* Creation repertoire si n'existe pas
*/
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
}
else if ($result == -99)
{
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
// print_r($_FILES);
} }
} else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
}
} }

View File

@ -77,28 +77,32 @@ if ($commande->fetch($_GET['id'],$_GET['ref']) < 0)
// Envoi fichier // Envoi fichier
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
$upload_dir = $conf->fournisseur->dir_output . "/commande/" . dol_sanitizeFileName($commande->ref); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir)) $upload_dir = $conf->fournisseur->dir_output . "/commande/" . dol_sanitizeFileName($commande->ref);
if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
}
else if ($result == -99)
{
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; }
// print_r($_FILES); else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
} }

View File

@ -65,32 +65,35 @@ $pagenext = $page + 1;
// Envoi fichier // Envoi fichier
if ($_POST['sendit'] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST['sendit'] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$facture = new FactureFournisseur($db); $facture = new FactureFournisseur($db);
if ($facture->fetch($facid)) if ($facture->fetch($facid))
{ {
$upload_dir = $conf->fournisseur->dir_output.'/facture/'.get_exdir($facture->id,2).$facture->id; $upload_dir = $conf->fournisseur->dir_output.'/facture/'.get_exdir($facture->id,2).$facture->id;
if (! is_dir($upload_dir)) create_exdir($upload_dir); if (create_exdir($upload_dir) >= 0)
if (is_dir($upload_dir))
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{ {
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
} }
else if ($result == -99) else
{ {
// Files infected by a virus
$langs->load("errors"); $langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>'; if ($resupload < 0) // Unknown error
} {
else if ($result < 0) $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
{ }
// Echec transfert (fichier depassant la limite ?) else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; {
// print_r($_FILES); $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
} }

View File

@ -86,6 +86,8 @@ $conn_id=0; // FTP connection ID
// Envoie fichier // Envoie fichier
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$result=$ecmdir->fetch($_REQUEST["section"]); $result=$ecmdir->fetch($_REQUEST["section"]);
if (! $result > 0) if (! $result > 0)
{ {
@ -95,32 +97,29 @@ if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
$relativepath=$ecmdir->getRelativePath(); $relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath; $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
if (! is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result=create_exdir($upload_dir); $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0);
} if (is_numeric($resupload) && $resupload > 0)
if (is_dir($upload_dir))
{
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0);
if ($result > 0)
{ {
//$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; //$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES); //print_r($_FILES);
$result=$ecmdir->changeNbOfFiles('+'); $result=$ecmdir->changeNbOfFiles('+');
} }
else if ($result == -99) else {
{
// File infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{
// Echec transfert (fichier depassant la limite ?)
$langs->load("errors"); $langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; if ($resupload < 0) // Unknown error
// print_r($_FILES); {
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
else else

View File

@ -191,6 +191,8 @@ if ($action == 'add_import_model')
if ($step == 3 && $datatoimport) if ($step == 3 && $datatoimport)
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
create_exdir($conf->import->dir_temp); create_exdir($conf->import->dir_temp);

View File

@ -108,6 +108,8 @@ class mailing_peche extends MailingTargets
{ {
global $conf,$langs,$_FILES; global $conf,$langs,$_FILES;
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
// For compatibility with Unix, MS-Dos or Macintosh // For compatibility with Unix, MS-Dos or Macintosh
ini_set('auto_detect_line_endings', true); ini_set('auto_detect_line_endings', true);
@ -115,13 +117,10 @@ class mailing_peche extends MailingTargets
$upload_dir=$conf->mailing->dir_temp; $upload_dir=$conf->mailing->dir_temp;
// Save file if (create_exdir($upload_dir) >= 0)
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir))
{ {
$result = dol_move_uploaded_file($_FILES['username']['tmp_name'], $upload_dir . "/" . $_FILES['username']['name'], 1); $resupload = dol_move_uploaded_file($_FILES['username']['tmp_name'], $upload_dir . "/" . $_FILES['username']['name'], 1, 0, $_FILES['username']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{ {
$cpt=0; $cpt=0;
@ -186,19 +185,21 @@ class mailing_peche extends MailingTargets
dol_syslog(get_class($this)."::add_to_target mailing ".$cpt." targets found"); dol_syslog(get_class($this)."::add_to_target mailing ".$cpt." targets found");
} }
else if ($result == -99) else
{ {
// Files infected by a virus
$langs->load("errors"); $langs->load("errors");
$this->error = $langs->trans("ErrorFileIsInfectedWithAVirus"); if ($resupload < 0) // Unknown error
return -1; {
} $this->error = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
else if ($result < 0) }
{ else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
// Echec transfert (fichier depassant la limite ?) {
$this->error = $langs->trans("ErrorFileNotUploaded"); $this->error = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
// print_r($_FILES); }
return -1; else // Known error
{
$this->error = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }

View File

@ -40,7 +40,13 @@ ErrorFileNotFound=File <b>%s</b> not found (Bad path, wrong permissions or acces
ErrorDirNotFound=Directory <b>%s</b> not found (Bad path, wrong permissions or access denied by PHP openbasedir or safe_mode parameter) ErrorDirNotFound=Directory <b>%s</b> not found (Bad path, wrong permissions or access denied by PHP openbasedir or safe_mode parameter)
ErrorFunctionNotAvailableInPHP=Function <b>%s</b> is required for this feature but is not available in this version/setup of PHP. ErrorFunctionNotAvailableInPHP=Function <b>%s</b> is required for this feature but is not available in this version/setup of PHP.
ErrorDirAlreadyExists=A directory with this name already exists. ErrorDirAlreadyExists=A directory with this name already exists.
ErrorFileAlreadyExists=A file with this name already exists.
ErrorPartialFile=File not received completely by server.
ErrorNoTmpDir=Temporary directy %s does not exists.
ErrorUploadBlockedByAddon=Upload blocked by a PHP/Apache plugin.
ErrorFileSizeTooLarge=File size is too large.
ErrorFieldCanNotContainSpecialCharacters=Field <b>%s</b> must not contains special characters. ErrorFieldCanNotContainSpecialCharacters=Field <b>%s</b> must not contains special characters.
WarningSafeModeOnCheckExecDir=Warning, PHP option <b>safe_mode</b> is on so command must be stored inside a directory declared by php parameter <b>safe_mode_exec_dir</b>.
WarningAllowUrlFopenMustBeOn=Parameter <b>allow_url_fopen</b> must be set to <b>on</b> in filer <b>php.ini</b> for having this module working completely. You must modify this file manually. WarningAllowUrlFopenMustBeOn=Parameter <b>allow_url_fopen</b> must be set to <b>on</b> in filer <b>php.ini</b> for having this module working completely. You must modify this file manually.
WarningBuildScriptNotRunned=Script <b>%s</b> was not yet ran to build graphics, or there is no data to show. WarningBuildScriptNotRunned=Script <b>%s</b> was not yet ran to build graphics, or there is no data to show.
WarningBookmarkAlreadyExists=A bookmark with this title or this target (URL) already exists. WarningBookmarkAlreadyExists=A bookmark with this title or this target (URL) already exists.

View File

@ -41,7 +41,13 @@ ErrorFileNotFound=Fichier <b>%s</b> introuvable (Mauvais chemin, permissions inc
ErrorDirNotFound=Répertoire <b>%s</b> introuvable (Mauvais chemin, permissions incorrectes ou accès interdit par le paramètre PHP openbasedir ou safe_mode) ErrorDirNotFound=Répertoire <b>%s</b> introuvable (Mauvais chemin, permissions incorrectes ou accès interdit par le paramètre PHP openbasedir ou safe_mode)
ErrorFunctionNotAvailableInPHP=La fonction <b>%s</b> est requise pour cette fonctionnalité mais n'est pas disponible dans cette version/installation de PHP. ErrorFunctionNotAvailableInPHP=La fonction <b>%s</b> est requise pour cette fonctionnalité mais n'est pas disponible dans cette version/installation de PHP.
ErrorDirAlreadyExists=Un répertoire portant ce nom existe déjà. ErrorDirAlreadyExists=Un répertoire portant ce nom existe déjà.
ErrorFileAlreadyExists=Un fichier portant ce nom existe déjà.
ErrorPartialFile=Fichier non reçu intégrallement par le serveur.
ErrorNoTmpDir=Répertoire temporaire de réception %s inexistant.
ErrorUploadBlockedByAddon=Upload bloqué par un plugin PHP/Apache.
ErrorFileSizeTooLarge=La taille du fichier est trop grande.
ErrorFieldCanNotContainSpecialCharacters=Le champ <b>%s</b> ne peut contenir de caractères spéciaux. ErrorFieldCanNotContainSpecialCharacters=Le champ <b>%s</b> ne peut contenir de caractères spéciaux.
WarningSafeModeOnCheckExecDir=Attention, l'option PHP <b>safe_mode</b> est active, la commande doit dont etre dans un répertoire déclaré dans le paramètre php <b>safe_mode_exec_dir</b>.
WarningAllowUrlFopenMustBeOn=Attention, le paramètre <b>allow_url_fopen</b> doit être positionné à <b>on</b> dans le fichier <b>php.ini</b> pour que ce module soit pleinement opérationnel. Vous devez modifier ce fichier manuellement. WarningAllowUrlFopenMustBeOn=Attention, le paramètre <b>allow_url_fopen</b> doit être positionné à <b>on</b> dans le fichier <b>php.ini</b> pour que ce module soit pleinement opérationnel. Vous devez modifier ce fichier manuellement.
WarningBuildScriptNotRunned=Le script <b>%s</b> n'a pas encore été lancé pour générer les graphiques ou il n'y a aucune donnée à afficher. WarningBuildScriptNotRunned=Le script <b>%s</b> n'a pas encore été lancé pour générer les graphiques ou il n'y a aucune donnée à afficher.
WarningBookmarkAlreadyExists=Un marque-page avec ce titre ou cette destination (URL) existe déjà. WarningBookmarkAlreadyExists=Un marque-page avec ce titre ou cette destination (URL) existe déjà.

View File

@ -396,7 +396,6 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not
$sql.= $db->encrypt($name,1); $sql.= $db->encrypt($name,1);
$sql.= ", ".$db->encrypt($value,1); $sql.= ", ".$db->encrypt($value,1);
$sql.= ",'".$type."',".$visible.",'".addslashes($note)."',".$entity.")"; $sql.= ",'".$type."',".$visible.",'".addslashes($note)."',".$entity.")";
dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG); dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql); $resql=$db->query($sql);
} }

View File

@ -60,37 +60,19 @@ class AntiVir
$return = 0; $return = 0;
$maxreclevel = 5 ; // maximal recursion level
$maxfiles = 1000; // maximal number of files to be scanned within archive
$maxratio = 200; // maximal compression ratio
$bz2archivememlim = 0; // limit memory usage for bzip2 (0/1)
$maxfilesize = 10485760; // archived files larger than this value (in bytes) will not be scanned
@set_time_limit($cfg['ExecTimeLimit']); @set_time_limit($cfg['ExecTimeLimit']);
$outputfile=$conf->admin->dir_temp.'/dol_avscan_file.out.'.session_id(); $outputfile=$conf->admin->dir_temp.'/dol_avscan_file.out.'.session_id();
$command=$conf->global->MAIN_ANTIVIRUS_COMMAND; $fullcommand=$this->getCliCommand($file);
$param=$conf->global->MAIN_ANTIVIRUS_PARAM; //$fullcommand='"c:\Program Files (x86)\ClamWin\bin\clamscan.exe" --database="C:\Program Files (x86)\ClamWin\lib" "c:\temp\aaa.txt"';
$param=preg_replace('/%maxreclevel/',$maxreclevel,$param);
$param=preg_replace('/%maxfiles/',$maxfiles,$param);
$param=preg_replace('/%maxratio/',$maxratiod,$param);
$param=preg_replace('/%bz2archivememlim/',$bz2archivememlim,$param);
$param=preg_replace('/%maxfilesize/',$maxfilesize,$param);
$param=preg_replace('/%file/',trim($file),$param);
if (! preg_match('/%file/',$conf->global->MAIN_ANTIVIRUS_PARAM))
$param=$param." ".escapeshellarg(trim($file));
if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command
$output=array(); $output=array();
$return_var=0; $return_var=0;
// Create a clean fullcommand // Create a clean fullcommand
$fullcommand=$command.' '.$param.' 2>&1';
dol_syslog("AntiVir::dol_avscan_file Run command=".$fullcommand); dol_syslog("AntiVir::dol_avscan_file Run command=".$fullcommand);
exec($fullcommand, $output, $return_var); exec($fullcommand, $output, $return_var);
/* /*
$handle = fopen($outputfile, 'w'); $handle = fopen($outputfile, 'w');
if ($handle) if ($handle)
@ -139,6 +121,44 @@ class AntiVir
return 1; return 1;
} }
/**
* \brief get full Command Line to run
* \param file File to scan
* \return string Full command line to run
*/
function getCliCommand($file)
{
global $conf;
$maxreclevel = 5 ; // maximal recursion level
$maxfiles = 1000; // maximal number of files to be scanned within archive
$maxratio = 200; // maximal compression ratio
$bz2archivememlim = 0; // limit memory usage for bzip2 (0/1)
$maxfilesize = 10485760; // archived files larger than this value (in bytes) will not be scanned
$command=$conf->global->MAIN_ANTIVIRUS_COMMAND;
$param=$conf->global->MAIN_ANTIVIRUS_PARAM;
$param=preg_replace('/%maxreclevel/',$maxreclevel,$param);
$param=preg_replace('/%maxfiles/',$maxfiles,$param);
$param=preg_replace('/%maxratio/',$maxratio,$param);
$param=preg_replace('/%bz2archivememlim/',$bz2archivememlim,$param);
$param=preg_replace('/%maxfilesize/',$maxfilesize,$param);
$param=preg_replace('/%file/',trim($file),$param);
if (! preg_match('/%file/',$conf->global->MAIN_ANTIVIRUS_PARAM))
$param=$param." ".escapeshellarg(trim($file));
if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command
$ret=$command.' '.$param;
//$ret=$command.' '.$param.' 2>&1';
return $ret;
}
} }
?> ?>

View File

@ -328,4 +328,124 @@ function dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
return $result; return $result;
} }
/**
* \brief Move an uploaded file after some controls.
* If there is errors (virus found, antivir in error, bad filename), file is not moved.
* \param src_file Source full path filename ($_FILES['field']['tmp_name'])
* \param dest_file Target full path filename
* \param allowoverwrite 1=Overwrite target file if it already exists
* \param disablevirusscan 1=Disable virus scan
* \param uploaderrorcode Value of upload error code ($_FILES['field']['error'])
* \return int >0 if OK, <0 or string if KO
*/
function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0)
{
global $conf;
$file_name = $dest_file;
// If an upload error has been reported
if ($uploaderrorcode)
{
switch($uploaderrorcode)
{
case UPLOAD_ERR_INI_SIZE: // 1
return 'ErrorFileSizeTooLarge';
break;
case UPLOAD_ERR_FORM_SIZE: // 2
return 'ErrorFileSizeTooLarge';
break;
case UPLOAD_ERR_PARTIAL: // 3
return 'ErrorPartialFile';
break;
case UPLOAD_ERR_NO_TMP_DIR: //
return 'ErrorNoTmpDir';
break;
case UPLOAD_ERR_CANT_WRITE:
return 'ErrorFailedToWriteInDir';
break;
case UPLOAD_ERR_EXTENSION:
return 'ErrorUploadBlockedByAddon';
break;
default:
break;
}
}
// If we need to make a virus scan
if (empty($disablevirusscan) && file_exists($src_file) && $conf->global->MAIN_ANTIVIRUS_COMMAND)
{
require_once(DOL_DOCUMENT_ROOT.'/lib/security.lib.php');
require_once(DOL_DOCUMENT_ROOT.'/lib/antivir.class.php');
$antivir=new AntiVir($db);
$result = $antivir->dol_avscan_file($src_file);
if ($result < 0) // If virus or error, we stop here
{
$reterrors=$antivir->errors;
dol_syslog("Functions.lib::dol_move_uploaded_file File ".$file_name." KO with antivir", LOG_WARNING);
return 'ErrorFileIsInfectedWithAVirus: '.join(',',$reterrors);
}
}
// Security:
// Disallow file with some extensions. We renamed them.
// Car si on a mis le rep documents dans un rep de la racine web (pas bien), cela permet d'executer du code a la demande.
if (preg_match('/\.htm|\.html|\.php|\.pl|\.cgi$/i',$file_name))
{
$file_name.= '.noexe';
}
// Security:
// On interdit fichiers caches, remontees de repertoire ainsi que les pipes dans les noms de fichiers.
if (preg_match('/^\./',$src_file) || preg_match('/\.\./',$src_file) || preg_match('/[<>|]/',$src_file))
{
dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING);
return -1;
}
// Security:
// On interdit fichiers caches, remontees de repertoire ainsi que les pipe dans
// les noms de fichiers.
if (preg_match('/^\./',$dest_file) || preg_match('/\.\./',$dest_file) || preg_match('/[<>|]/',$dest_file))
{
dol_syslog("Refused to deliver file ".$dest_file, LOG_WARNING);
return -2;
}
// The file functions must be in OS filesystem encoding.
$src_file_osencoded=dol_osencode($src_file);
$file_name_osencoded=dol_osencode($file_name);
// Check if destination dir is writable
// TODO
// Check if destination file already exists
if (! $allowoverwrite)
{
if (file_exists($file_name_osencoded))
{
dol_syslog("Functions.lib::dol_move_uploaded_file File ".$file_name." already exists", LOG_WARNING);
return 'ErrorFileAlreadyExists';
}
}
// Move file
$return=move_uploaded_file($src_file_osencoded, $file_name_osencoded);
if ($return)
{
if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
dol_syslog("Functions.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
return 1; // Success
}
else
{
dol_syslog("Functions.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR);
return -3; // Unknown error
}
return 1;
}
?> ?>

View File

@ -1958,95 +1958,6 @@ function dol_print_error_email()
} }
/**
* \brief Move an uploaded file after some controls.
* If there is errors (virus found, antivir in error, bad filename), file is not moved.
* \param src_file Source filename
* \param dest_file Target filename
* \param allowoverwrite Overwrite if exists
* \param disablevirusscan Disable virus scan
* \return int >0 if OK, <0 if KO (an array with virus or errors if virus found or errors)
*/
function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0)
{
global $conf;
$file_name = $dest_file;
// If we need to make a virus scan
if (empty($disablevirusscan) && file_exists($src_file) && $conf->global->MAIN_ANTIVIRUS_COMMAND)
{
require_once(DOL_DOCUMENT_ROOT.'/lib/security.lib.php');
require_once(DOL_DOCUMENT_ROOT.'/lib/antivir.class.php');
$antivir=new AntiVir($db);
$result = $antivir->dol_avscan_file($src_file);
if ($result < 0) // If virus or error, we stop here
{
$reterrors=$antivir->errors;
dol_syslog("Functions.lib::dol_move_uploaded_file File ".$file_name." KO with antivir", LOG_WARNING);
//return $reterrors;
return -99;
}
}
// Security:
// Disallow file with some extensions. We renamed them.
// Car si on a mis le rep documents dans un rep de la racine web (pas bien), cela permet d'executer du code a la demande.
if (preg_match('/\.htm|\.html|\.php|\.pl|\.cgi$/i',$file_name))
{
$file_name.= '.noexe';
}
// Security:
// On interdit fichiers caches, remontees de repertoire ainsi que les pipes dans les noms de fichiers.
if (preg_match('/^\./',$src_file) || preg_match('/\.\./',$src_file) || preg_match('/[<>|]/',$src_file))
{
dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING);
return -1;
}
// Security:
// On interdit fichiers caches, remontees de repertoire ainsi que les pipe dans
// les noms de fichiers.
if (preg_match('/^\./',$dest_file) || preg_match('/\.\./',$dest_file) || preg_match('/[<>|]/',$dest_file))
{
dol_syslog("Refused to deliver file ".$dest_file, LOG_WARNING);
return -2;
}
// The file functions must be in OS filesystem encoding.
$src_file_osencoded=dol_osencode($src_file);
$file_name_osencoded=dol_osencode($file_name);
// Check if destination file already exists
if (! $allowoverwrite)
{
if (file_exists($file_name_osencoded))
{
dol_syslog("Functions.lib::dol_move_uploaded_file File ".$file_name." already exists", LOG_WARNING);
return -3;
}
}
// Move file
$return=move_uploaded_file($src_file_osencoded, $file_name_osencoded);
if ($return)
{
if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
dol_syslog("Functions.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
return 1;
}
else
{
dol_syslog("Functions.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR);
return -4;
}
return 1;
}
/** /**
* \brief Show title line of an array * \brief Show title line of an array
* \param name libelle champ * \param name libelle champ

View File

@ -2382,6 +2382,8 @@ class Product extends CommonObject
*/ */
function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120) function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120)
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
$dir = $sdir .'/'. get_exdir($this->id,2) . $this->id ."/photos"; $dir = $sdir .'/'. get_exdir($this->id,2) . $this->id ."/photos";
create_exdir($dir); create_exdir($dir);

View File

@ -77,32 +77,32 @@ $modulepart='produit';
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
/* require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
* Creation repertoire si n'existe pas
*/
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
}
else if ($result == -99)
{
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
// print_r($_FILES);
} }
} else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
}
} }

View File

@ -69,28 +69,32 @@ if (! $project->fetch($_GET['id'],$_GET['ref']) > 0)
// Envoi fichier // Envoi fichier
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
$upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($project->ref); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
if (! is_dir($upload_dir)) create_exdir($upload_dir);
if (is_dir($upload_dir)) $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($project->ref);
if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
}
else if ($result == -99)
{
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; }
// print_r($_FILES); else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
} }

View File

@ -84,27 +84,30 @@ else
// Envoi fichier // Envoi fichier
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
if (! is_dir($upload_dir)) create_exdir($upload_dir); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
if (is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
}
else if ($result == -99)
{
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?) $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; }
// print_r($_FILES); else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
} }

View File

@ -73,27 +73,30 @@ $courrier_dir = $conf->societe->dir_output . "/courrier/" . get_exdir($socid) ;
// Envoie fichier // Envoie fichier
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
if (! is_dir($upload_dir)) create_exdir($upload_dir); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
if (is_dir($upload_dir)) if (create_exdir($upload_dir) >= 0)
{ {
$result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
if ($result > 0) if (is_numeric($resupload) && $resupload > 0)
{ {
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>'; $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
//print_r($_FILES);
} }
else if ($result == -99) else
{
// Files infected by a virus
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else if ($result < 0)
{ {
// Echec transfert (fichier depassant la limite ?) $langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>'; if ($resupload < 0) // Unknown error
// print_r($_FILES); {
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
} }
} }
} }

View File

@ -222,6 +222,8 @@ if ($_GET["action"] == 'removegroup' && $caneditfield)
if ($_POST["action"] == 'update' && ! $_POST["cancel"]) if ($_POST["action"] == 'update' && ! $_POST["cancel"])
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
if ($caneditfield) // Case we can edit all field if ($caneditfield) // Case we can edit all field
{ {
$message=""; $message="";
@ -258,8 +260,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
$edituser->phenix_login = $_POST["phenix_login"]; $edituser->phenix_login = $_POST["phenix_login"];
$edituser->phenix_pass = $_POST["phenix_pass"]; $edituser->phenix_pass = $_POST["phenix_pass"];
$edituser->entity = $_POST["entity"]; $edituser->entity = $_POST["entity"];
if (! empty($_FILES['photo']['name'])) $edituser->photo = $_FILES['photo']['name'];
$edituser->photo = $_FILES['photo']['name'];
$ret=$edituser->update($user); $ret=$edituser->update($user);
if ($ret < 0) if ($ret < 0)
@ -295,7 +296,9 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
if (@is_dir($dir)) if (@is_dir($dir))
{ {
$newfile=$dir.'/'.$_FILES['photo']['name']; $newfile=$dir.'/'.$_FILES['photo']['name'];
if (! dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1) > 0) $result=dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1,0,$_FILES['photo']['error']);
if (! $result > 0)
{ {
$message .= '<div class="error">'.$langs->trans("ErrorFailedToSaveFile").'</div>'; $message .= '<div class="error">'.$langs->trans("ErrorFailedToSaveFile").'</div>';
} }