diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php
index 741dd98de6dfeece248913b7405d3dd0ce960f69..1aea8f9e37be91a13d22188954d8ef9c7fc4947b 100644
--- a/htdocs/core/lib/product.lib.php
+++ b/htdocs/core/lib/product.lib.php
@@ -57,11 +57,6 @@ function product_prepare_head($object, $user)
 		$h++;
 	}
 
-	$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$object->id;
-	$head[$h][1] = $langs->trans("Photos");
-	$head[$h][2] = 'photos';
-	$h++;
-
 	// Show category tab
 	if (! empty($conf->categorie->enabled) && $user->rights->categorie->lire)
 	{
@@ -116,14 +111,19 @@ function product_prepare_head($object, $user)
     // $this->tabs = array('entity:-tabname);   												to remove a tab
     complete_head_from_modules($conf,$langs,$object,$head,$h,'product');
 
-	// Attachments
+	$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$object->id;
+	$head[$h][1] = $langs->trans("Photos");
+	$head[$h][2] = 'photos';
+	$h++;
+
+    // Attachments
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 	if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
     elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
 	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$'));
     $head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$object->id;
 	$head[$h][1] = $langs->trans('Documents');
-	if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')';
+	if($nbFiles > 0) $head[$h][1].= ' <span class="badge">'.$nbFiles.'</span>';
 	$head[$h][2] = 'documents';
 	$h++;
 
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index ba179aef616f8d97e855e8598f93f5d8dc095e4e..0778046c4311a4c1caf59405ab9159a625efdc57 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -3101,10 +3101,14 @@ class Product extends CommonObject
 	 */
 	function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120)
 	{
+		global $conf;
+
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 
 		$result = 0;
-		$dir = $sdir .'/'. get_exdir($this->id,2) . $this->id ."/photos";
+
+		$dir = $sdir;
+		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $dir .= '/'. get_exdir($this->id,2) . $this->id ."/photos";
 
 		dol_mkdir($dir);
 
@@ -3156,8 +3160,8 @@ class Product extends CommonObject
 	{
 		include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
 
-		$pdir = get_exdir($this->id,2) . $this->id ."/photos/";
-		$dir = $sdir . '/'. $pdir;
+		$dir = $sdir;
+		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $dir .= '/'. get_exdir($this->id,2) . $this->id ."/photos";
 
 		$nbphoto=0;
 
@@ -3199,8 +3203,19 @@ class Product extends CommonObject
 		include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
 		include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php';
 
-		$pdir = get_exdir($this->id,2) . $this->id ."/photos/";
-		$dir = $sdir . '/'. $pdir;
+		$dir = $sdir . '/';
+		$pdir = '/';
+		if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
+		{
+			$dir .= get_exdir($this->id,2) . $this->id ."/photos/";
+			$pdir .= get_exdir($this->id,2) . $this->id ."/photos/";
+		}
+		else
+		{
+			$dir .= $this->ref.'/';
+			$pdir .= $this->ref.'/';
+		}
+
 		$dirthumb = $dir.'thumbs/';
 		$pdirthumb = $pdir.'thumbs/';