diff --git a/htdocs/product.class.php b/htdocs/product.class.php index ddc8b355e7d..bbc53459bfc 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -2338,6 +2338,25 @@ class Product return $tabobj; } + /** + * \brief Efface la photo du produit et sa vignette + * \param file Chemin de l'image + */ + function delete_photo($file) + { + // On efface l'image d'origine + unlink($file); + + // Si elle existe, on efface la vignette + if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$file,$regs)) + { + $photo_vignette=eregi_replace($regs[0],'',$file).'_small'.$regs[0]; + if (file_exists($photo_vignette)) + { + unlink($photo_vignette); + } + } + } /** * \brief Charge indicateurs this->nb de tableau de bord diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php index d5b49e8b053..8dc9fe419db 100644 --- a/htdocs/product/photos.php +++ b/htdocs/product/photos.php @@ -49,7 +49,7 @@ if (!$user->rights->produit->lire) accessforbidden(); * Actions */ -if ($_POST["sendit"] && $conf->upload != 0) +if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && $conf->upload != 0) { if ($_GET["id"]) { @@ -66,7 +66,8 @@ if ($_POST["sendit"] && $conf->upload != 0) if ($_GET["action"] == 'delete' && $_GET["file"]) { - unlink($conf->produit->dir_output."/".$_GET["file"]); + $product = new Product($db); + $product->delete_photo($conf->produit->dir_output."/".$_GET["file"]); } @@ -181,19 +182,22 @@ if ($_GET["id"] || $_GET["ref"]) if ($obj['photo_vignette']) { $filename=$obj['photo_vignette']; - $viewfilename=$obj['photo']; } else { $filename=$obj['photo']; } + + // Nom affiché + $viewfilename=$obj['photo']; + print ''; print ''; print '
'.$langs->trans("File").': '.dolibarr_trunc($viewfilename,16); if ($user->rights->produit->creer) { - print '
'.''.img_delete().''; + print '
'.''.img_delete().''; } if ($nbbyrow) print ''; if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print '';