manto07m 3 роки тому
батько
коміт
1bc33798be
3 змінених файлів з 143 додано та 97 видалено
  1. 21 0
      pdfConverter.html
  2. 24 0
      pdfConverter.php
  3. 98 97
      script/js/video-list.js

+ 21 - 0
pdfConverter.html

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta content="text/html; charset=utf-8"
+        http-equiv="content-type">
+  <title>PDF轉檔工具</title>
+</head>
+<body>
+  <h1>PDF轉檔工具</h1>
+  <form action="pdfConverter.php"
+        enctype="multipart/form-data"
+        method="post">
+    選擇Office文件或PPT: <input accept=".docx,.doc,.pptx,.ppt"
+          id="my_file"
+          name="my_file"
+          type="file"> <input name="submit"
+          type="submit"
+          value="上傳文件">
+  </form>
+</body>
+</html>

+ 24 - 0
pdfConverter.php

@@ -0,0 +1,24 @@
+<?php
+require './vendor/autoload.php';
+
+use NcJoes\OfficeConverter\OfficeConverter;
+
+$target_dir = "../uploads/";
+$file = $_FILES['my_file']['name'];
+$path = pathinfo($file);
+$filename = $path['filename'];
+$ext = $path['extension'];
+$temp_name = $_FILES['my_file']['tmp_name'];
+$path_filename_ext = $target_dir . $filename . "." . $ext;
+$filePdf = $target_dir . $filename . ".pdf";
+if (file_exists($path_filename_ext)) {
+    echo "檔案已存在!<br>";
+} else {
+    move_uploaded_file($temp_name, $path_filename_ext);
+    echo "上傳成功! 已轉檔成功!<br>";
+    $converter = new OfficeConverter($path_filename_ext, $target_dir, "soffice.bin ", false);
+    $converter->convertTo($filePdf);
+}
+echo "<a href='" . $target_dir . $filePdf . "' target='_blank'>預覽PDF</a><br>";
+echo "<a download href='" . $target_dir . $filePdf . "' >下載PDF</a>";
+echo "<br><a href='pdfConverter.html' >返回上傳</a>";

+ 98 - 97
script/js/video-list.js

@@ -1,112 +1,113 @@
-$(document).ready(function () {
-    if(folderFromVideoPlay != ""){
-        initList(folderFromVideoPlay);
-    }else{
-        initList("videos");
-    }
-});
-
-function initList(dir) {
-    $.ajax({
-        url: "./script/php/video/getDir.php",
-        type: "POST",
-        data: {
-            dir: dir,
-        },
-        dataType: "json"
-    }).done(function (result) {
-
-        $("#video-list").empty();
-        dir_names = result["dir_names"];
-        file_tables = result["file_tables"];
-        if (result["parent"] != undefined)
-            parent = result["parent"];
-            
-        //directory
-        for (i = 0; i < dir_names.length; i++) {
-            $("#video-list").append('<div class="col-md-3">' +
-                '<section class="panel">' +
-                "<a href='#' onclick='initList(\"" + dir_names[i]["dir_name"] + "\")'>" +
-                '<img class="video-active" src="./assets/images/folder-icon.png">' +
-                '</a>' +
-                '<div class="panel-body" id="">' +
-                '<div class="video-text">' +
-                "<p style='font-size: 20px;'><i class='fa fa-folder'></i><a class='video-font' href='#' onclick='initList(\"" + dir_names[i]["dir_name"] + "\")'>" + dir_names[i]["dir_name"] + "</a></p>" +
-                '</div>' +
-                '</div>' +
-                '</section>' +
-                '</div>');
+(function ($) {
+    $(document).ready(function () {
+        if (folderFromVideoPlay != "") {
+            initList(folderFromVideoPlay);
+        } else {
+            initList("videos");
         }
+    });
+
+    function initList(dir) {
+        $.ajax({
+            url: "./script/php/video/getDir.php",
+            type: "POST",
+            data: {
+                dir: dir,
+            },
+            dataType: "json"
+        }).done(function (result) {
+            $("#video-list").empty();
+            dir_names = result["dir_names"];
+            file_tables = result["file_tables"];
+            if (result["parent"] != undefined)
+                parent = result["parent"];
 
-        //video
-        for (j = 0; j < file_tables.length; j++) {
-            if (file_tables[j]["file_path"].includes(".m3u8")) {
+            //directory
+            for (i = 0; i < dir_names.length; i++) {
                 $("#video-list").append('<div class="col-md-3">' +
                     '<section class="panel">' +
-                    "<a href='#' onclick='getVideo(" + file_tables[j]["id"] + ",\"" + file_tables[j]["file_path"].split("/")[file_tables[j]["file_path"].split("/").length-2] + "\")'>" +
-                    '<img style="aspect-ratio: 4/3;" class="video-static" src="' + file_tables[j]["file_path"].replace("m3u8", "jpg") + '">' +
-                    '<img style="aspect-ratio: 4/3;" class="video-active" src="' + file_tables[j]["file_path"].replace("m3u8", "gif") +
-                    '">' +
+                    "<a href='#' onclick='initList(\"" + dir_names[i]["dir_name"] + "\")'>" +
+                    '<img class="video-active" src="./assets/images/folder-icon.png">' +
                     '</a>' +
                     '<div class="panel-body" id="">' +
                     '<div class="video-text">' +
-                    "<p style='font-size: 20px;'><i class='fa fa-video-camera'></i><a class='video-font' href='#' onclick='getVideo(" + file_tables[j]["id"] + ",\"" + file_tables[j]["file_path"].split("/")[file_tables[j]["file_path"].split("/").length-2] + "\")'>" + file_tables[j]["title"] + "</a></p>" +
+                    "<p style='font-size: 20px;'><i class='fa fa-folder'></i><a class='video-font' href='#' onclick='initList(\"" + dir_names[i]["dir_name"] + "\")'>" + dir_names[i]["dir_name"] + "</a></p>" +
                     '</div>' +
                     '</div>' +
                     '</section>' +
                     '</div>');
-            }else if(file_tables[j]["file_path"].includes(".pdf")){
-                if($("#description").length <= 0){
-                    $("#video-list").prepend('<div class="col-md-12">' +
-                    '<section class="panel" id="video-body">' +
-                    '<div class="panel-body" style="color:black;">' +
-                    '<h4>課程簡介</h4>' +
-                    '<text id="description"></text>' +
-                    '</div>' +
-                    '</section>' +
-                    '</div>');
-                    getVideoInfo(file_tables[j]["id"]);
+            }
+
+            //video
+            for (j = 0; j < file_tables.length; j++) {
+                if (file_tables[j]["file_path"].includes(".m3u8")) {
+                    $("#video-list").append('<div class="col-md-3">' +
+                        '<section class="panel">' +
+                        "<a href='#' onclick='getVideo(" + file_tables[j]["id"] + ",\"" + file_tables[j]["file_path"].split("/")[file_tables[j]["file_path"].split("/").length - 2] + "\")'>" +
+                        '<img style="aspect-ratio: 4/3;" class="video-static" src="' + file_tables[j]["file_path"].replace("m3u8", "jpg") + '">' +
+                        '<img style="aspect-ratio: 4/3;" class="video-active" src="' + file_tables[j]["file_path"].replace("m3u8", "gif") +
+                        '">' +
+                        '</a>' +
+                        '<div class="panel-body" id="">' +
+                        '<div class="video-text">' +
+                        "<p style='font-size: 20px;'><i class='fa fa-video-camera'></i><a class='video-font' href='#' onclick='getVideo(" + file_tables[j]["id"] + ",\"" + file_tables[j]["file_path"].split("/")[file_tables[j]["file_path"].split("/").length - 2] + "\")'>" + file_tables[j]["title"] + "</a></p>" +
+                        '</div>' +
+                        '</div>' +
+                        '</section>' +
+                        '</div>');
+                } else if (file_tables[j]["file_path"].includes(".pdf")) {
+                    if ($("#description").length <= 0) {
+                        $("#video-list").prepend('<div class="col-md-12">' +
+                            '<section class="panel" id="video-body">' +
+                            '<div class="panel-body" style="color:black;">' +
+                            '<h4>課程簡介</h4>' +
+                            '<text id="description"></text>' +
+                            '</div>' +
+                            '</section>' +
+                            '</div>');
+                        getVideoInfo(file_tables[j]["id"]);
+                    }
+                    $("#video-list").append('<div class="col-md-3">' +
+                        '<section class="panel">' +
+                        "<a target='_blank' href='" + file_tables[j]["file_path"] + "'>" +
+                        '<img style="aspect-ratio: 4/3;" class="video-active" src="' + file_tables[j]["file_path"].replace("pdf", "jpg") + '">' +
+                        '</a>' +
+                        '<div class="panel-body" id="">' +
+                        '<div class="video-text">' +
+                        "<p style='font-size: 20px;'><i class='fa fa-file-pdf-o'></i><a class='video-font' target='_blank' href='" + file_tables[j]["file_path"] + "'>" + file_tables[j]["title"] + "</a></p>" +
+                        '</div>' +
+                        '</div>' +
+                        '</section>' +
+                        '</div>');
                 }
-                $("#video-list").append('<div class="col-md-3">' +
-                '<section class="panel">' +
-                "<a target='_blank' href='" + file_tables[j]["file_path"] + "'>" +
-                '<img style="aspect-ratio: 4/3;" class="video-active" src="' + file_tables[j]["file_path"].replace("pdf", "jpg") + '">' +
-                '</a>' +
-                '<div class="panel-body" id="">' +
-                '<div class="video-text">' +
-                "<p style='font-size: 20px;'><i class='fa fa-file-pdf-o'></i><a class='video-font' target='_blank' href='" + file_tables[j]["file_path"] + "'>" + file_tables[j]["title"] + "</a></p>" +
-                '</div>' +
-                '</div>' +
-                '</section>' +
-                '</div>');
             }
-        }
-    }).error(function (error) {
-        console.log(error);
-    });
-}
+        }).error(function (error) {
+            console.log(error);
+        });
+    }
 
-function getVideo(id, folder) {
-    $.redirect('./video-play.php', {
-        'id': id,
-        'folder': folder
-    });
-}
+    function getVideo(id, folder) {
+        $.redirect('./video-play.php', {
+            'id': id,
+            'folder': folder
+        });
+    }
 
-function getVideoInfo(id) {
-    $.ajax({
-        url: "./script/php/video/getInfo.php",
-        type: "POST",
-        data: {
-            id: id,
-        },
-        dataType: "json"
-    }).done(function (result) {
-        if (result[0].description == null) {
-            result[0].description = "暫無描述";
-        }
-        $("#description").text(result[0].description);
-    }).error(function (error) {
-        console.log(error);
-    });
-}
+    function getVideoInfo(id) {
+        $.ajax({
+            url: "./script/php/video/getInfo.php",
+            type: "POST",
+            data: {
+                id: id,
+            },
+            dataType: "json"
+        }).done(function (result) {
+            if (result[0].description == null) {
+                result[0].description = "暫無描述";
+            }
+            $("#description").text(result[0].description);
+        }).error(function (error) {
+            console.log(error);
+        });
+    }
+})(jQuery);