From 5c76af21b2d67f052f41099d233c08687f395732 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 30 Jul 2007 12:37:06 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20d=E9placement=20de=20la=20v=E9rification?= =?UTF-8?q?=20du=20type=20d'image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/lib/functions.inc.php | 6 ++++++ htdocs/product.class.php | 20 +++++++++++--------- htdocs/product/photos.php | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 97ceb63be4b..452fed9b8ac 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -2955,6 +2955,11 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){ // Si le fichier passé en paramètre n'existe pas return 'Le fichier '.$file.' n\'a pas été trouvé sur le serveur.'; } + elseif(!eregi('(\.jpg|\.png)$',$files['name'])) + { + // Todo: Ajouter création vignette pour les autres formats d'images + return 'Le fichier '.$file.' n\'ai pas géré pour le moment.'; + } elseif(empty($file)){ // Si le fichier n'a pas été indiqué return 'Nom du fichier non renseigné.'; @@ -2982,6 +2987,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){ dolibarr_syslog("Product Create $dirthumb"); create_exdir($dirthumb); } + // Initialisation des variables selon l'extension de l'image switch($infoImg[2]){ diff --git a/htdocs/product.class.php b/htdocs/product.class.php index a240b2ea2e9..ed2444faeda 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -2123,11 +2123,11 @@ class Product /** * \brief Déplace fichier uploadé sous le nom $files dans le répertoire sdir * \param sdir Répertoire destination finale - * \param $files Nom du fichier uploadé + * \param $file Nom du fichier uploadé * \param maxWidth Largeur maximum que dois faire la miniature (160 par défaut) * \param maxHeight Hauteur maximum que dois faire la miniature (120 par défaut) */ - function add_photo($sdir, $files, $maxWidth = 160, $maxHeight = 120) + function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120) { $dir = $sdir .'/'. get_exdir($this->id,2) . $this->id ."/"; $dir .= "photos/"; @@ -2140,13 +2140,12 @@ class Product if (file_exists($dir)) { - $originImage = $dir . $files['name']; + $originImage = $dir . $file['name']; // Crée fichier en taille origine - doliMoveFileUpload($files['tmp_name'], $originImage); - - // Todo: Ajouter création vignette pour les autres formats d'images - if (file_exists($originImage) && eregi('(\.jpg|\.png)$',$files['name'])) + doliMoveFileUpload($file['tmp_name'], $originImage); + + if (file_exists($originImage)) { // Crée fichier en taille vignette $this->add_thumb($originImage,$maxWidth,$maxHeight); @@ -2157,13 +2156,16 @@ class Product /** * \brief Génère la vignette * \param sdir Répertoire destination finale - * \param file Nom du fichier d'origine + * \param file Chemin du fichier d'origine * \param maxWidth Largeur maximum que dois faire la miniature (160 par défaut) * \param maxHeight Hauteur maximum que dois faire la miniature (120 par défaut) */ function add_thumb($file, $maxWidth = 160, $maxHeight = 120) { - vignette($file,$maxWidth,$maxHeight); + if (file_exists($file)) + { + vignette($file,$maxWidth,$maxHeight); + } } /** diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php index ee0fc926918..946e0428470 100644 --- a/htdocs/product/photos.php +++ b/htdocs/product/photos.php @@ -203,7 +203,7 @@ if ($_GET["id"] || $_GET["ref"]) print '
'.$langs->trans("File").': '.dolibarr_trunc($viewfilename,16); print '
'; // On propose la génération de la vignette si elle n'existe pas - if (!$obj['photo_vignette']) + if (!$obj['photo_vignette'] && eregi('(\.jpg|\.png)$',$obj['photo'])) { print ''.img_refresh($langs->trans('RegenerateThumb')).'  '; }