From b4881e629b03e71faf6012fe8a55ae0eca939ced Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 27 Sep 2022 19:21:29 +0200 Subject: [PATCH 1/2] FIX missing error message if image size too large --- htdocs/admin/company.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index c72976f829e..f3fc12c8ae4 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -107,7 +107,7 @@ if (($action == 'update' && !GETPOST("cancel", 'alpha')) $dirforimage = $conf->mycompany->dir_output.'/logos/'; $arrayofimages = array('logo', 'logo_squarred'); - + //var_dump($_FILES); exit; foreach ($arrayofimages as $varforimage) { if ($_FILES[$varforimage]["name"] && !preg_match('/(\.jpeg|\.jpg|\.png)$/i', $_FILES[$varforimage]["name"])) { // Logo can be used on a lot of different places. Only jpg and png can be supported. $langs->load("errors"); @@ -115,7 +115,8 @@ if (($action == 'update' && !GETPOST("cancel", 'alpha')) break; } - if ($_FILES[$varforimage]["tmp_name"]) { + // Remove to check file size to large + /*if ($_FILES[$varforimage]["tmp_name"]) {*/ $reg = array(); if (preg_match('/([^\\/:]+)$/i', $_FILES[$varforimage]["name"], $reg)) { $original_file = $reg[1]; @@ -165,6 +166,9 @@ if (($action == 'update' && !GETPOST("cancel", 'alpha')) $langs->load("errors"); $tmparray = explode(':', $result); setEventMessages($langs->trans('ErrorFileIsInfectedWithAVirus', $tmparray[1]), null, 'errors'); + } elseif (preg_match('/^ErrorFileSizeTooLarge/', $result)) { + $error++; + setEventMessages($langs->trans("ErrorFileSizeTooLarge"), null, 'errors'); } else { $error++; setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors'); @@ -175,7 +179,7 @@ if (($action == 'update' && !GETPOST("cancel", 'alpha')) setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors'); } } - } + /*}*/ } dolibarr_set_const($db, "MAIN_INFO_SOCIETE_MANAGERS", GETPOST("MAIN_INFO_SOCIETE_MANAGERS", 'alphanohtml'), 'chaine', 0, '', $conf->entity); From 310f95f17351c009d560dae189c4dffcc5421f01 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 27 Sep 2022 17:31:22 +0000 Subject: [PATCH 2/2] Fixing style errors. --- htdocs/admin/company.php | 96 ++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index f3fc12c8ae4..4f4af520df7 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -118,67 +118,67 @@ if (($action == 'update' && !GETPOST("cancel", 'alpha')) // Remove to check file size to large /*if ($_FILES[$varforimage]["tmp_name"]) {*/ $reg = array(); - if (preg_match('/([^\\/:]+)$/i', $_FILES[$varforimage]["name"], $reg)) { - $original_file = $reg[1]; + if (preg_match('/([^\\/:]+)$/i', $_FILES[$varforimage]["name"], $reg)) { + $original_file = $reg[1]; - $isimage = image_format_supported($original_file); - if ($isimage >= 0) { - dol_syslog("Move file ".$_FILES[$varforimage]["tmp_name"]." to ".$dirforimage.$original_file); - if (!is_dir($dirforimage)) { - dol_mkdir($dirforimage); + $isimage = image_format_supported($original_file); + if ($isimage >= 0) { + dol_syslog("Move file ".$_FILES[$varforimage]["tmp_name"]." to ".$dirforimage.$original_file); + if (!is_dir($dirforimage)) { + dol_mkdir($dirforimage); + } + $result = dol_move_uploaded_file($_FILES[$varforimage]["tmp_name"], $dirforimage.$original_file, 1, 0, $_FILES[$varforimage]['error']); + if ($result > 0) { + $constant = "MAIN_INFO_SOCIETE_LOGO"; + if ($varforimage == 'logo_squarred') { + $constant = "MAIN_INFO_SOCIETE_LOGO_SQUARRED"; } - $result = dol_move_uploaded_file($_FILES[$varforimage]["tmp_name"], $dirforimage.$original_file, 1, 0, $_FILES[$varforimage]['error']); - if ($result > 0) { - $constant = "MAIN_INFO_SOCIETE_LOGO"; - if ($varforimage == 'logo_squarred') { - $constant = "MAIN_INFO_SOCIETE_LOGO_SQUARRED"; - } - dolibarr_set_const($db, $constant, $original_file, 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, $constant, $original_file, 'chaine', 0, '', $conf->entity); - // Create thumbs of logo (Note that PDF use original file and not thumbs) - if ($isimage > 0) { - // Create thumbs - //$object->addThumbs($newfile); // We can't use addThumbs here yet because we need name of generated thumbs to add them into constants. TODO Check if need such constants. We should be able to retrieve value with get... + // Create thumbs of logo (Note that PDF use original file and not thumbs) + if ($isimage > 0) { + // Create thumbs + //$object->addThumbs($newfile); // We can't use addThumbs here yet because we need name of generated thumbs to add them into constants. TODO Check if need such constants. We should be able to retrieve value with get... - // Create small thumb, Used on logon for example - $imgThumbSmall = vignette($dirforimage.$original_file, $maxwidthsmall, $maxheightsmall, '_small', $quality); - if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbSmall, $reg)) { - $imgThumbSmall = $reg[1]; // Save only basename - dolibarr_set_const($db, $constant."_SMALL", $imgThumbSmall, 'chaine', 0, '', $conf->entity); - } else { - dol_syslog($imgThumbSmall); - } - - // Create mini thumb, Used on menu or for setup page for example - $imgThumbMini = vignette($dirforimage.$original_file, $maxwidthmini, $maxheightmini, '_mini', $quality); - if (image_format_supported($imgThumbMini) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbMini, $reg)) { - $imgThumbMini = $reg[1]; // Save only basename - dolibarr_set_const($db, $constant."_MINI", $imgThumbMini, 'chaine', 0, '', $conf->entity); - } else { - dol_syslog($imgThumbMini); - } + // Create small thumb, Used on logon for example + $imgThumbSmall = vignette($dirforimage.$original_file, $maxwidthsmall, $maxheightsmall, '_small', $quality); + if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbSmall, $reg)) { + $imgThumbSmall = $reg[1]; // Save only basename + dolibarr_set_const($db, $constant."_SMALL", $imgThumbSmall, 'chaine', 0, '', $conf->entity); } else { - dol_syslog("ErrorImageFormatNotSupported", LOG_WARNING); + dol_syslog($imgThumbSmall); + } + + // Create mini thumb, Used on menu or for setup page for example + $imgThumbMini = vignette($dirforimage.$original_file, $maxwidthmini, $maxheightmini, '_mini', $quality); + if (image_format_supported($imgThumbMini) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbMini, $reg)) { + $imgThumbMini = $reg[1]; // Save only basename + dolibarr_set_const($db, $constant."_MINI", $imgThumbMini, 'chaine', 0, '', $conf->entity); + } else { + dol_syslog($imgThumbMini); } - } elseif (preg_match('/^ErrorFileIsInfectedWithAVirus/', $result)) { - $error++; - $langs->load("errors"); - $tmparray = explode(':', $result); - setEventMessages($langs->trans('ErrorFileIsInfectedWithAVirus', $tmparray[1]), null, 'errors'); - } elseif (preg_match('/^ErrorFileSizeTooLarge/', $result)) { - $error++; - setEventMessages($langs->trans("ErrorFileSizeTooLarge"), null, 'errors'); } else { - $error++; - setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors'); + dol_syslog("ErrorImageFormatNotSupported", LOG_WARNING); } - } else { + } elseif (preg_match('/^ErrorFileIsInfectedWithAVirus/', $result)) { $error++; $langs->load("errors"); - setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors'); + $tmparray = explode(':', $result); + setEventMessages($langs->trans('ErrorFileIsInfectedWithAVirus', $tmparray[1]), null, 'errors'); + } elseif (preg_match('/^ErrorFileSizeTooLarge/', $result)) { + $error++; + setEventMessages($langs->trans("ErrorFileSizeTooLarge"), null, 'errors'); + } else { + $error++; + setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors'); } + } else { + $error++; + $langs->load("errors"); + setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors'); } + } /*}*/ }