Fix: Several fix on photo upload when file format is wrong

This commit is contained in:
Laurent Destailleur 2011-06-22 09:11:00 +00:00
parent bbf4372f50
commit 32da27f003
6 changed files with 85 additions and 66 deletions

View File

@ -245,7 +245,7 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adhe
$adh->amount = $_POST["amount"]; $adh->amount = $_POST["amount"];
if (GETPOST('deletephoto')) $adh->photo=''; if (GETPOST('deletephoto')) $adh->photo='';
$adh->photo = ($_FILES['photo']['name']?dol_sanitizeFileName($_FILES['photo']['name']):$adh->oldcopy->photo); elseif (! empty($_FILES['photo']['name'])) $adh->photo = dol_sanitizeFileName($_FILES['photo']['name']);
// Get status and public property // Get status and public property
$adh->statut = $_POST["statut"]; $adh->statut = $_POST["statut"];
@ -277,7 +277,11 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adhe
$result=$adh->update($user,0,$nosyncuser,$nosyncuserpass); $result=$adh->update($user,0,$nosyncuser,$nosyncuserpass);
if ($result >= 0 && ! sizeof($adh->errors)) if ($result >= 0 && ! sizeof($adh->errors))
{ {
if (GETPOST('deletephoto') && $adh->photo) $dir= $conf->adherent->dir_output . '/' . get_exdir($adh->id,2,0,1).'/photos';
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK)
{
if (GETPOST('deletephoto'))
{ {
$fileimg=$conf->adherent->dir_output.'/'.get_exdir($adh->id,2,0,1).'/photos/'.$adh->photo; $fileimg=$conf->adherent->dir_output.'/'.get_exdir($adh->id,2,0,1).'/photos/'.$adh->photo;
$dirthumbs=$conf->adherent->dir_output.'/'.get_exdir($adh->id,2,0,1).'/photos/thumbs'; $dirthumbs=$conf->adherent->dir_output.'/'.get_exdir($adh->id,2,0,1).'/photos/thumbs';
@ -285,11 +289,9 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adhe
dol_delete_dir_recursive($dirthumbs); dol_delete_dir_recursive($dirthumbs);
} }
if (!empty($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name'])) if (image_format_supported($_FILES['photo']['name']) > 0)
{ {
$dir= $conf->adherent->dir_output . '/' . get_exdir($adh->id,2,0,1).'/photos/'; dol_mkdir($dir);
create_exdir($dir);
if (@is_dir($dir)) if (@is_dir($dir))
{ {
@ -310,6 +312,11 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adhe
} }
} }
} }
else
{
$errmsgs[] = "ErrorBadImageFormat";
}
}
$_GET["rowid"]=$adh->id; $_GET["rowid"]=$adh->id;
$_REQUEST["action"]=''; $_REQUEST["action"]='';

View File

@ -29,6 +29,7 @@ ErrorSupplierCodeRequired=Supplier code required
ErrorSupplierCodeAlreadyUsed=Supplier code already used ErrorSupplierCodeAlreadyUsed=Supplier code already used
ErrorBadParameters=Bad parameters ErrorBadParameters=Bad parameters
ErrorBadValueForParameter=Wrong value '%s' for parameter incorrect '%s' ErrorBadValueForParameter=Wrong value '%s' for parameter incorrect '%s'
ErrorBadImageFormat=Image file has not a supported format
ErrorFailedToWriteInDir=Failed to write in directory %s ErrorFailedToWriteInDir=Failed to write in directory %s
ErrorFoundBadEmailInFile=Found incorrect email syntax for %s lines in file (example line %s with email=%s) ErrorFoundBadEmailInFile=Found incorrect email syntax for %s lines in file (example line %s with email=%s)
ErrorUserCannotBeDelete=User can not be deleted. May be it is associated on Dolibarr entities. ErrorUserCannotBeDelete=User can not be deleted. May be it is associated on Dolibarr entities.

View File

@ -30,6 +30,7 @@ ErrorSupplierCodeRequired=Code fournisseur obligatoire
ErrorSupplierCodeAlreadyUsed=Code fournisseur déjà utilisé ErrorSupplierCodeAlreadyUsed=Code fournisseur déjà utilisé
ErrorBadParameters=Paramètres incorrects ErrorBadParameters=Paramètres incorrects
ErrorBadValueForParameter=Valeur '%s' incorrecte pour le paramètre '%s' ErrorBadValueForParameter=Valeur '%s' incorrecte pour le paramètre '%s'
ErrorBadImageFormat=L'image n'a pas un format reconnu
ErrorFailedToWriteInDir=Impossible d'écrire dans le répertoire %s ErrorFailedToWriteInDir=Impossible d'écrire dans le répertoire %s
ErrorFoundBadEmailInFile=Syntaxe de mail incorrecte trouvée pour %s lignes dans le fichier (exemple ligne %s avec email=%s) ErrorFoundBadEmailInFile=Syntaxe de mail incorrecte trouvée pour %s lignes dans le fichier (exemple ligne %s avec email=%s)
ErrorUserCannotBeDelete=L'utilisateur ne peut pas être supprimé. Peut-être est-il associé à des éléments de Dolibarr. ErrorUserCannotBeDelete=L'utilisateur ne peut pas être supprimé. Peut-être est-il associé à des éléments de Dolibarr.

View File

@ -618,6 +618,8 @@ function dol_delete_dir($dir,$nophperrors=0)
function dol_delete_dir_recursive($dir,$count=0,$nophperrors=0) function dol_delete_dir_recursive($dir,$count=0,$nophperrors=0)
{ {
dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG); dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG);
if (dol_is_dir($dir))
{
$dir_osencoded=dol_osencode($dir); $dir_osencoded=dol_osencode($dir);
if ($handle = opendir("$dir_osencoded")) if ($handle = opendir("$dir_osencoded"))
{ {
@ -644,6 +646,7 @@ function dol_delete_dir_recursive($dir,$count=0,$nophperrors=0)
$count++; $count++;
//echo "removing $dir<br>\n"; //echo "removing $dir<br>\n";
} }
}
//echo "return=".$count; //echo "return=".$count;
return $count; return $count;

View File

@ -302,7 +302,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
global $conf,$langs; global $conf,$langs;
dol_syslog("vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality." targetformat=".$targetformat); dol_syslog("vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality." outdir=".$outdir." targetformat=".$targetformat);
// Clean parameters // Clean parameters
$file=trim($file); $file=trim($file);
@ -311,23 +311,27 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $
if (! $file) if (! $file)
{ {
// Si le fichier n'a pas ete indique // Si le fichier n'a pas ete indique
return 'Bad parameter file'; return 'ErrorBadParameters';
} }
elseif (! file_exists($file)) elseif (! file_exists($file))
{ {
// Si le fichier passe en parametre n'existe pas // Si le fichier passe en parametre n'existe pas
dol_syslog($langs->trans("ErrorFileNotFound",$file),LOG_ERR);
return $langs->trans("ErrorFileNotFound",$file); return $langs->trans("ErrorFileNotFound",$file);
} }
elseif(image_format_supported($file) < 0) elseif(image_format_supported($file) < 0)
{ {
return 'This file '.$file.' does not seem to be an image format file name.'; dol_syslog('This file '.$file.' does not seem to be an image format file name.',LOG_WARNING);
return 'ErrorBadImageFormat';
} }
elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){ elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){
// Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) // Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
dol_syslog('Wrong value for parameter maxWidth',LOG_ERR);
return 'Wrong value for parameter maxWidth'; return 'Wrong value for parameter maxWidth';
} }
elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){ elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){
// Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) // Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
dol_syslog('Wrong value for parameter maxHeight',LOG_ERR);
return 'Wrong value for parameter maxHeight'; return 'Wrong value for parameter maxHeight';
} }

View File

@ -194,7 +194,7 @@ else
$soc->default_lang = $_POST["default_lang"]; $soc->default_lang = $_POST["default_lang"];
if (GETPOST('deletephoto')) $soc->logo = ''; if (GETPOST('deletephoto')) $soc->logo = '';
$soc->logo = dol_sanitizeFileName($_FILES['photo']['name']); else if (! empty($_FILES['photo']['name'])) $soc->logo = dol_sanitizeFileName($_FILES['photo']['name']);
// Check parameters // Check parameters
if (empty($_POST["cancel"])) if (empty($_POST["cancel"]))
@ -320,26 +320,25 @@ else
exit; exit;
} }
$oldsoc=new Societe($db); $soc->oldcopy=dol_clone($soc);
$result=$oldsoc->fetch($socid);
// To not set code if third party is not concerned. But if it had values, we keep them. // To not set code if third party is not concerned. But if it had values, we keep them.
if (empty($soc->client) && empty($oldsoc->code_client)) $soc->code_client=''; if (empty($soc->client) && empty($soc->oldcopy->code_client)) $soc->code_client='';
if (empty($soc->fournisseur)&& empty($oldsoc->code_fournisseur)) $soc->code_fournisseur=''; if (empty($soc->fournisseur)&& empty($soc->oldcopy->code_fournisseur)) $soc->code_fournisseur='';
//var_dump($soc);exit; //var_dump($soc);exit;
$result = $soc->update($socid,$user,1,$oldsoc->codeclient_modifiable(),$oldsoc->codefournisseur_modifiable()); $result = $soc->update($socid,$user,1,$soc->oldcopy->codeclient_modifiable(),$soc->oldcopy->codefournisseur_modifiable());
if ($result <= 0) if ($result <= 0)
{ {
$error = $soc->error; $errors = $soc->errors; $error = $soc->error; $errors = $soc->errors;
} }
### Gestion du logo de la société ### Gestion du logo de la société
$dir = $conf->societe->dir_output."/".$soc->id."/logos/"; $dir = $conf->societe->dir_output."/".$soc->id."/logos";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK) if ($file_OK)
{ {
if (GETPOST('deletephoto') && $soc->logo) if (GETPOST('deletephoto'))
{ {
$fileimg=$conf->societe->dir_output.'/'.$soc->id.'/logos/'.$soc->logo; $fileimg=$conf->societe->dir_output.'/'.$soc->id.'/logos/'.$soc->logo;
$dirthumbs=$conf->societe->dir_output.'/'.$soc->id.'/logos/thumbs'; $dirthumbs=$conf->societe->dir_output.'/'.$soc->id.'/logos/thumbs';
@ -347,9 +346,9 @@ else
dol_delete_dir_recursive($dirthumbs); dol_delete_dir_recursive($dirthumbs);
} }
if (image_format_supported($_FILES['photo']['name'])) if (image_format_supported($_FILES['photo']['name']) > 0)
{ {
create_exdir($dir); dol_mkdir($dir);
if (@is_dir($dir)) if (@is_dir($dir))
{ {
@ -372,6 +371,10 @@ else
} }
} }
} }
else
{
$errors[] = "ErrorBadImageFormat";
}
} }
### Gestion du logo de la société ### Gestion du logo de la société