diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index ac3d8e967a2ad9cd621e4764aa550e34bc00da17..2ac3eed44ef3459ad265b53c65b0418cc0315bde 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -3170,9 +3170,12 @@ class Product extends CommonObject
 	function is_photo_available($sdir)
 	{
 		include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
+		
+		global $conf;
 
 		$dir = $sdir;
-		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $dir .= '/'. get_exdir($this->id,2) . $this->id ."/photos";
+		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $dir .= '/'. get_exdir($this->id,2) . $this->id ."/photos/";
+		else $dir .= '/'.dol_sanitizeFileName($this->ref).'/';
 
 		$nbphoto=0;