Browse Source

Merge pull request #10010 from atm-john/Fix_cat_photo_upload

Fix event message on upload category picture fail
Laurent Destailleur 6 years ago
parent
commit
f3228dc4f8
2 changed files with 19 additions and 2 deletions
  1. 18 1
      htdocs/categories/photos.php
  2. 1 1
      htdocs/core/class/html.formfile.class.php

+ 18 - 1
htdocs/categories/photos.php

@@ -69,7 +69,24 @@ if ($id > 0)
 if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
 {
     if ($object->id) {
-	    $object->add_photo($upload_dir, $_FILES['userfile']);
+        
+        $file = $_FILES['userfile'];
+        if (is_array($file['name']) && count($file['name']) > 0)
+        {
+            foreach ($file['name'] as $i => $name)
+            {
+                if(empty($file['tmp_name'][$i]) || intval($conf->global->MAIN_UPLOAD_DOC) * 1000 <= filesize($file['tmp_name'][$i]) )
+                {
+                    setEventMessage($file['name'][$i] .' : '. $langs->trans(empty($file['tmp_name'][$i])? 'ErrorFailedToSaveFile' : 'MaxSizeForUploadedFiles' ) );
+                    unset($file['name'][$i],$file['type'][$i],$file['tmp_name'][$i],$file['error'][$i],$file['size'][$i]);
+                }
+            }
+        }
+        
+        if(!empty($file['tmp_name'])){
+            $object->add_photo($upload_dir, $file);
+        }
+        
     }
 }
 

+ 1 - 1
htdocs/core/class/html.formfile.class.php

@@ -1635,7 +1635,7 @@ class FormFile
 	 */
 	private function _formAjaxFileUpload($object)
 	{
-		global $langs;
+		global $langs, $conf;
 
 		// PHP post_max_size
 		$post_max_size				= ini_get('post_max_size');