CauseFX 3 лет назад
Родитель
Сommit
c833615000
2 измененных файлов с 56 добавлено и 55 удалено
  1. 25 27
      api/classes/organizr.class.php
  2. 31 28
      api/pages/settings-image-manager.php

+ 25 - 27
api/classes/organizr.class.php

@@ -2045,36 +2045,34 @@ class Organizr
 	public function uploadImage()
 	{
 		$filesCheck = array_filter($_FILES);
-		if (!empty($filesCheck)) {
-			if ($_FILES['file']['tmp_name'] == '') {
-				$this->setResponse(500, 'File upload error');
-				return false;
-			}
-			if (strpos($_FILES['file']['type'], 'image/') === false) {
-				$this->setResponse(403, 'File Type not approved', $_FILES['file']['type']);
-				return false;
-			}
-			if (!$this->approvedFileType($_FILES['file']['tmp_name'])) {
-				$this->setResponse(403, 'File Type not approved', $_FILES['file']['tmp_name']);
-				return false;
-			}
-			if ($this->approvedFileExtension($_FILES['file']['name'])) {
-				ini_set('upload_max_filesize', '10M');
-				ini_set('post_max_size', '10M');
-				$tempFile = $_FILES['file']['tmp_name'];
-				$targetPath = $this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'userTabs' . DIRECTORY_SEPARATOR;
-				$this->makeDir($targetPath);
-				$targetFile = $targetPath . $this->sanitizeUserString($_FILES['file']['name']);
-				$this->setAPIResponse(null, pathinfo($_FILES['file']['name'], PATHINFO_BASENAME) . ' has been uploaded', null);
-				return move_uploaded_file($tempFile, $targetFile);
-			} else {
-				$this->setResponse(403, 'File Extension not approved');
-				return false;
-			}
-		} else {
+		if (empty($filesCheck)) {
 			$this->setResponse(500, 'No File was uploaded');
 			return false;
 		}
+		if ($_FILES['file']['tmp_name'] == '') {
+			$this->setResponse(500, 'File upload error');
+			return false;
+		}
+		if (strpos($_FILES['file']['type'], 'image/') === false) {
+			$this->setResponse(403, 'File Type not image', $_FILES['file']['type']);
+			return false;
+		}
+		if (!$this->approvedFileType($_FILES['file']['tmp_name'])) {
+			$this->setResponse(403, 'File Type not approved', $_FILES['file']['tmp_name']);
+			return false;
+		}
+		if (!$this->approvedFileExtension($_FILES['file']['name'])) {
+			$this->setResponse(403, 'File Extension not approved');
+			return false;
+		}
+		ini_set('upload_max_filesize', '10M');
+		ini_set('post_max_size', '10M');
+		$tempFile = $_FILES['file']['tmp_name'];
+		$targetPath = $this->root . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'userTabs' . DIRECTORY_SEPARATOR;
+		$this->makeDir($targetPath);
+		$targetFile = $targetPath . $this->sanitizeUserString($_FILES['file']['name']);
+		$this->setAPIResponse(null, pathinfo($_FILES['file']['name'], PATHINFO_BASENAME) . ' has been uploaded', null);
+		return move_uploaded_file($tempFile, $targetFile);
 	}
 
 	public function formatPingHost($host)

+ 31 - 28
api/pages/settings-image-manager.php

@@ -14,40 +14,43 @@ function get_page_settings_image_manager($Organizr)
 	return '
 <script>
 	buildImageManagerView();
-    var myDropzone = new Dropzone("#new-image-form", {
-      url: "api/v2/image",
-      headers:{ "formKey": local("g","formKey") },
-      init: function() {
-        this.on("complete", function(file) {
-            if(file["status"] === "success"){
-                buildImageManagerView();
-            }else{
-                let response = JSON.parse(file.xhr.responseText);
-            	message("Upload Error", response.response.message,activeInfo.settings.notifications.position,"#FFF","error","5000");
-            }
-        });
-      }
-    });
+	const myDropzone = new Dropzone("#new-image-form", {
+		url: "api/v2/image",
+		headers:{ "formKey": local("g","formKey") },
+		init: function() {
+		this.on("complete", function(file) {
+			if(file["status"] === "success"){
+				buildImageManagerView();
+			}else{
+				let response = JSON.parse(file.xhr.responseText);
+				message("Upload Error", response.response.message,activeInfo.settings.notifications.position,"#FFF","error","5000");
+			}
+		});
+		this.on("error", function(file, response) {
+			$(file.previewElement).find(".dz-error-message").text(response.response.message);
+		});
+	  }
+	});
 </script>
 <div class="panel bg-org panel-info">
-    <div class="panel-heading">
+	<div class="panel-heading">
 		<span lang="en">View Images</span>
-        <button type="button" class="btn btn-info btn-circle pull-right popup-with-form m-r-5" href="#new-image-form" data-effect="mfp-3d-unfold"><i class="fa fa-upload"></i> </button>
+		<button type="button" class="btn btn-info btn-circle pull-right popup-with-form m-r-5" href="#new-image-form" data-effect="mfp-3d-unfold"><i class="fa fa-upload"></i> </button>
+	</div>
+	<div class="panel-wrapper collapse in" aria-expanded="true">
+		<div class="panel-body bg-org" >
+			<div id="gallery-content">
+				<div id="gallery-content-center" class="settings-image-manager-list"></div>
+			</div>
+		</div>
 	</div>
-    <div class="panel-wrapper collapse in" aria-expanded="true">
-        <div class="panel-body bg-org" >
-        	<div id="gallery-content">
-                <div id="gallery-content-center" class="settings-image-manager-list"></div>
-            </div>
-        </div>
-    </div>
 </div>
 <form action="#" id="new-image-form" class="mfp-hide white-popup-block mfp-with-anim dropzone" enctype="multipart/form-data">
-    <h1 lang="en">Upload Image</h1>
-    <div class="fallback">
-        <input name="file" type="file" multiple />
-    </div>
-    <div class="clearfix"></div>
+	<h1 lang="en">Upload Image</h1>
+	<div class="fallback">
+		<input name="file" type="file" multiple />
+	</div>
+	<div class="clearfix"></div>
 </form>
 ';
 }