From 274063f00255d801a000d131ccf563edb6cb21b6 Mon Sep 17 00:00:00 2001 From: Regis Houssin <regis@dolibarr.fr> Date: Mon, 30 Jul 2007 11:55:12 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20on=20stocke=20les=20miniatures=20dans=20?= =?UTF-8?q?un=20r=E9pertoire=20"thumb"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/lib/functions.inc.php | 12 ++++++++++-- htdocs/product.class.php | 32 ++++++++++++++++++++------------ htdocs/product/photos.php | 2 +- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 44fbbbc2d3c..9bf5090f396 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -2971,10 +2971,18 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){ $fichier = realpath($file); // Chemin canonique absolu de l'image $dir = dirname($file).'/'; // Chemin du dossier contenant l'image + $dirthumb = $dir.'thumb/'; // Chemin du dossier contenant les vignettes $infoImg = getimagesize($fichier); // R�cup�ration des infos de l'image $imgWidth = $infoImg[0]; // Largeur de l'image $imgHeight = $infoImg[1]; // Hauteur de l'image + // On cr�e le r�pertoire contenant les vignettes + if (! file_exists($dirthumb)) + { + dolibarr_syslog("Product Create $dirthumb"); + create_exdir($dirthumb); + } + // Initialisation des variables selon l'extension de l'image switch($infoImg[2]){ case 2: @@ -3007,9 +3015,9 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120){ $imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight); // Cr�ation de la vignette imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Ins�re l'image de base redimensionn�e - + $fileName = basename($file, $extImg); // Nom du fichier sans son extension - $imgThumbName = $dir.$fileName.'_small'.$extImg; // Chemin complet du fichier de la vignette + $imgThumbName = $dirthumb.$fileName.'_small'.$extImg; // Chemin complet du fichier de la vignette //Cr�ation du fichier de la vignette $fp = fopen($imgThumbName, "w"); diff --git a/htdocs/product.class.php b/htdocs/product.class.php index e57a1ba2761..aaf4acd8dfd 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -2157,13 +2157,13 @@ class Product /** * \brief G�n�re la vignette * \param sdir R�pertoire destination finale - * \param files Nom du fichier upload� + * \param file Nom 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($files, $maxWidth = 160, $maxHeight = 120) + function add_thumb($file, $maxWidth = 160, $maxHeight = 120) { - vignette($files,$maxWidth,$maxHeight); + vignette($file,$maxWidth,$maxHeight); } /** @@ -2235,6 +2235,8 @@ class Product { $pdir = get_exdir($this->id,2) . $this->id ."/photos/"; $dir = $sdir . '/'. $pdir; + $dirthumb = $dir.'thumb/'; + $pdirthumb = $pdir.'thumb/'; $nbphoto=0; if (file_exists($dir)) @@ -2245,7 +2247,7 @@ class Product { $photo=''; - if (is_file($dir.$file) && !eregi('\_small',$file)) + if (is_file($dir.$file)) { $nbphoto++; $photo = $file; @@ -2266,8 +2268,8 @@ class Product print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo).'" alt="Taille origine" target="_blank">'; // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine - if ($photo_vignette && is_file($dir.$photo_vignette)) { - print '<img border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo_vignette).'">'; + if ($photo_vignette && is_file($dirthumb.$photo_vignette)) { + print '<img border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdirthumb.$photo_vignette).'">'; } else { print '<img border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo).'">'; @@ -2315,6 +2317,8 @@ class Product { $nbphoto=0; $tabobj=array(); + + $dirthumb = $dir.'thumb/'; if (file_exists($dir)) { @@ -2322,7 +2326,7 @@ class Product while (($file = readdir($handle)) != false) { - if (is_file($dir.$file) && !eregi('\_small',$file)) + if (is_file($dir.$file)) { $nbphoto++; $photo = $file; @@ -2337,7 +2341,7 @@ class Product // Objet $obj=array(); $obj['photo']=$photo; - if ($photo_vignette && is_file($dir.$photo_vignette)) $obj['photo_vignette']=$photo_vignette; + if ($photo_vignette && is_file($dirthumb.$photo_vignette)) $obj['photo_vignette']=$photo_vignette; else $obj['photo_vignette']=""; $tabobj[$nbphoto-1]=$obj; @@ -2359,16 +2363,20 @@ class Product */ function delete_photo($file) { + $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine + $dirthumb = $dir.'/thumb/'; // Chemin du dossier contenant la vignette + $filename = eregi_replace($dir,'',$file); // Nom du fichier + // On efface l'image d'origine unlink($file); // Si elle existe, on efface la vignette - if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$file,$regs)) + if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$filename,$regs)) { - $photo_vignette=eregi_replace($regs[0],'',$file).'_small'.$regs[0]; - if (file_exists($photo_vignette)) + $photo_vignette=eregi_replace($regs[0],'',$filename).'_small'.$regs[0]; + if (file_exists($dirthumb.$photo_vignette)) { - unlink($photo_vignette); + unlink($dirthumb.$photo_vignette); } } } diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php index 0776382e5ce..2030b97e39e 100644 --- a/htdocs/product/photos.php +++ b/htdocs/product/photos.php @@ -187,7 +187,7 @@ if ($_GET["id"] || $_GET["ref"]) // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine if ($obj['photo_vignette']) { - $filename=$obj['photo_vignette']; + $filename='thumb/'.$obj['photo_vignette']; } else { -- GitLab