浏览代码

上船工具 正是路徑

manto07m 3 年之前
父节点
当前提交
3d2a1c23aa
共有 3 个文件被更改,包括 74 次插入34 次删除
  1. 26 8
      api-upload.php
  2. 10 6
      script/php/api_upload.php
  3. 38 20
      script/php/api_video_tool.php

+ 26 - 8
api-upload.php

@@ -374,6 +374,13 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 		var isDuplicate = false;
 		vm.mount('.body');
 		addUserImage(userName.charAt(0), role);
+		const stack_bar_top = {
+			"dir1": "down",
+			"dir2": "right",
+			"push": "top",
+			"spacing1": 0,
+			"spacing2": 0
+		};
 		const revit = ['通用', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022', '2023'];
 		const dynamo = ['1.3', '2.0', '2.1', '2.2', '2.3', '2.13'];
 		$(document).ready(function() {
@@ -406,14 +413,13 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 			});
 
 			$("#APIName").on('change', function() {
-				console.log($(this).val())
 				isDuplicate = checkDuplicate($(this).val())
 				if (isDuplicate) {
 					$("#APIName-Form").append(`<label id="APIName-label" class="error">此API已經匯入過</label>`);
 					$("#APIName-Form").addClass("has-error");
 				} else {
 					$("#APIName-label").remove();
-					$("#APIName-Form").attr("class","form-group");
+					$("#APIName-Form").attr("class", "form-group");
 				}
 			})
 
@@ -421,14 +427,14 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 				e.preventDefault();
 
 				if (isDuplicate) {
-					alert('尚未提供上傳不同版本功能,請勿重複上傳!');
+					showNotification('警告','尚未提供上傳不同版本功能,請勿重複上傳!','error');
 					return;
 				}
 				if ($("#files").val() === "") {
-					alert('請先選擇上傳檔案!');
+					showNotification('警告','請先選擇上傳檔案!','error');
 					return;
 				}
-				
+
 
 				var formData = new FormData();
 				$(".form-control").each(function(ele) {
@@ -446,7 +452,7 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 					contentType: false,
 					dataType: 'text', // 回傳的資料格式
 					success: function(data) {
-						console.log(data);
+						showNotification('成功','轉檔上傳成功!','success');
 					},
 					xhr: function() {
 						var xhr = new window.XMLHttpRequest(); // 建立xhr(XMLHttpRequest)物件
@@ -456,6 +462,9 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 								var percentVal = Math.round(percentComplete * 100) + "%";
 								$("#bar").text(percentVal); // 進度條百分比文字
 								$("#bar").width(percentVal); // 進度條顏色
+								if(percentVal == '100%'){
+									showNotification('提示','上傳成功!請稍待轉檔完成','info');
+								}
 							}
 						}, false);
 						return xhr; // 注意必須將xhr(XMLHttpRequest)物件回傳
@@ -479,16 +488,25 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 				async: false,
 				dataType: "json"
 			}).done(function(result) {
-				
 				if (result != "") {
 					isDuplicate = true;
 				}
-
 			}).error(function(error) {
 				console.log(error);
 			});
 			return isDuplicate;
 		}
+
+		function showNotification(title,text,type) {
+			var notice = new PNotify({
+				title: title,
+				text: text,
+				type: type,
+				addclass: 'stack-bar-top',
+				stack: stack_bar_top,
+				width: "100%"
+			});
+		}
 	</script>
 	<?php include("bim-support-body.html"); ?>
 

+ 10 - 6
script/php/api_upload.php

@@ -2,9 +2,11 @@
 include("connectSQL_Component.php");
 $keys = [];
 $values = [];
+$APIName = "";
 
 if (isset($_FILES['files'])) {
 	if ($_POST['APIName'] != "" && $_POST['software'] != "") {
+		$APIName = $_POST['APIName'];
 		$foldername = '../../上傳測試/' . $_POST['software'] . '/' . $_POST['APIName'];
 		if (!is_dir($foldername)) mkdir($foldername);
 		for ($count = 0; $count < count($_FILES['files']['name']); $count++) {
@@ -13,15 +15,17 @@ if (isset($_FILES['files'])) {
 		$placeholder = "?";
 		$count = 0;
 		foreach ($_POST as $key => $value) {
-			array_push($keys, "[" . htmlspecialchars($key) . "]");
-			array_push($values, htmlspecialchars($value));
-			$count++;
+			if ($key != "") {
+				array_push($keys, "[" . htmlspecialchars($key) . "]");
+				array_push($values, htmlspecialchars($value));
+				$count++;
+			}
 		}
 		$placeholder = $placeholder . str_repeat(",?", $count - 1);
 		$params = implode(",", $keys);
-		$sql =  "IF NOT EXISTS (SELECT [APIName] FROM [API_Table_Test] WHERE [APIName] = '{$_POST["APIName"]}')
+		$sql =  "IF NOT EXISTS (SELECT [APIName] FROM [API_Table] WHERE [APIName] = '{$_POST["APIName"]}')
             BEGIN
-			INSERT INTO [API_Table_Test]
+			INSERT INTO [API_Table]
 			(
 				" . $params . "
 			)
@@ -39,7 +43,7 @@ if (isset($_FILES['files'])) {
 				}
 			}
 		} else {
-			echo ('success');
+			include("api_video_tool.php");
 		}
 	} else
 		echo "Upload folder name is empty";

+ 38 - 20
script/php/api_video_tool.php

@@ -3,6 +3,9 @@ set_time_limit(0);
 require '../../vendor/autoload.php';
 $GLOBALS["videoExt"] = array('mp4', 'avi');
 $GLOBALS["pdfExt"] = array('doc', 'docx', 'ppt', 'pptx', 'pdf');
+$isAJAX = false;
+$GLOBALS["output"] = "";
+$GLOBALS["ajax"] = [];
 
 use NcJoes\OfficeConverter\OfficeConverter;
 use Streaming\Representation;
@@ -15,9 +18,22 @@ $ffmpeg = Streaming\FFMpeg::create([
 
 $GLOBALS["ffmpeg"] = $ffmpeg;
 
-$root = '../../assets';
-$folder = 'API';
+$root = '../../assets/API/Universal';
+//$root = '../../上傳測試/Revit';
+$folder = 'Revit/托放元件';
+
+if (isset($_POST["APIName"])) {
+    $folder = $APIName;
+    $root .= ('/'.$_POST['software']);
+    $isAJAX = true;
+}
 FindPath($root, $folder, $ffmpeg);
+if (!$isAJAX) {
+    echo ($GLOBALS["output"]);
+}else{
+    echo (implode(",",$GLOBALS["ajax"]));
+}
+
 
 function ConvertVideo($file_path, $ffmpeg)
 {
@@ -33,10 +49,12 @@ function ConvertVideo($file_path, $ffmpeg)
             ->x264()
             ->setHlsTime(300)
             ->addRepresentations([$r_1080p])
-            ->save("../." . $dir_name . '/' . $file_name . ".m3u8");      
-        echo "<span style='color:red;'>";
-        echo "   " . $ext . " ==> m3u8";
-        echo "</span>";
+            ->save("../." . $dir_name . '/' . $file_name . ".m3u8");
+
+        $GLOBALS["output"] .= "<span style='color:red;'>";
+        $GLOBALS["output"] .= "   " . $ext . " ==> m3u8";
+        $GLOBALS["output"] .= "</span>";
+        array_push($GLOBALS["ajax"],$file_name);
     }
 }
 
@@ -48,9 +66,9 @@ function ConvertPdf($file_path)
     if (!file_exists("../." . $dir_name . '/' . $file_name . ".pdf")) {
         $converter = new OfficeConverter("../." . $file_path, "./", "soffice.bin ", false);
         $converter->convertTo("../." . $dir_name . '/' . $file_name . ".pdf");
-        echo "<span style='color:red;'>";
-        echo "   " . $ext . " ==> pdf";
-        echo "</span>";
+        $GLOBALS["output"] .= "<span style='color:red;'>";
+        $GLOBALS["output"] .= "   " . $ext . " ==> pdf";
+        $GLOBALS["output"] .= "</span>";
     }
     if (!file_exists("../." . $dir_name . '/' . $file_name . ".jpg")) {
         $root = $_SERVER['DOCUMENT_ROOT']  . '/BIM-Monitor'  . substr($dir_name, 1)  . '/' . $file_name;
@@ -61,9 +79,9 @@ function ConvertPdf($file_path)
         $im->writeImage($root . '.jpg');
         $im->clear();
         $im->destroy();
-        echo "<span style='color:red;'>";
-        echo "    pdf ==> jpg";
-        echo "</span>";
+        $GLOBALS["output"] .= "<span style='color:red;'>";
+        $GLOBALS["output"] .= "    pdf ==> jpg";
+        $GLOBALS["output"] .= "</span>";
     }
 }
 
@@ -73,14 +91,14 @@ function FindPath($root, $folder, $ffmpeg)
     $rootPath = $root . '/' . $folder;
     $paths = array_diff(scandir($root . '/' . $folder), array('.', '..', 'Thumbs.db'));
     natsort($paths);
-    echo ("<ul>");
+    $GLOBALS["output"] .= ("<ul>");
     foreach ($paths as $path) {
         if (str_contains($path, '.')) {
-            echo ("<li data-jstree='{ " . '"type" : "file"' . " }' >");
+            $GLOBALS["output"] .= ("<li data-jstree='{ " . '"type" : "file"' . " }' >");
             $title = explode(".", $path)[0];
             $file_path = substr($rootPath, 4) . "/" . $path;
             $path = "title:" . $title . "path:" . $file_path . "  dir_id:" . $folder;
-            echo ($path);
+            $GLOBALS["output"] .= ($path);
 
             $ext = pathinfo($file_path, PATHINFO_EXTENSION);
             if (in_array($ext, $GLOBALS["videoExt"])) {
@@ -88,13 +106,13 @@ function FindPath($root, $folder, $ffmpeg)
             } else if (in_array($ext, $GLOBALS["pdfExt"])) {
                 //ConvertPdf($file_path);
             }
-            echo ("</li>");
+            $GLOBALS["output"] .= ("</li>");
         } else {
-            echo ("<li>");
-            echo ("dir_name: " . $path . "parent:  " . $folder);
+            $GLOBALS["output"] .= ("<li>");
+            $GLOBALS["output"] .= ("dir_name: " . $path . "parent:  " . $folder);
             FindPath($rootPath, $path, $ffmpeg);
-            echo ("</li>");
+            $GLOBALS["output"] .= ("</li>");
         }
     }
-    echo ("</ul>");
+    $GLOBALS["output"] .= ("</ul>");
 }