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 ''; // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine - if ($photo_vignette && is_file($dir.$photo_vignette)) { - print ''; + if ($photo_vignette && is_file($dirthumb.$photo_vignette)) { + print ''; } else { print ''; @@ -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 {