From ddf6140c322523596fb2f3845c0abd70cebf6613 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Wed, 1 Apr 2020 21:53:36 +0200 Subject: [PATCH] added pic upload --- js/index.js | 14 +++++++++++++- php/movie.php | 42 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/js/index.js b/js/index.js index 0d6f83d..9b4bea5 100644 --- a/js/index.js +++ b/js/index.js @@ -3,7 +3,19 @@ Req.ready((event) => { console.log(dta); for (const ii in dta.data) { document.getElementsByClassName("mediawrapper").item(0).insertAdjacentHTML('beforeend', ` -
${dta.data[ii].url}
`); +
${dta.data[ii].url}
`); // } }); + + Req.post("php/movie.php", "action=storePic", function (dta) { + console.log(dta); + }); + + Req.post("php/movie.php", "action=readPic", function (dta) { + console.log(dta); + }); + + Req.post("php/movie.php", "action=getDbSize", function (dta) { + console.log(dta); + }); }); \ No newline at end of file diff --git a/php/movie.php b/php/movie.php index ecc47e2..58cf2f0 100644 --- a/php/movie.php +++ b/php/movie.php @@ -2,11 +2,16 @@ $servername = "192.168.0.177"; $username = "myuser"; $password = "1qayxsw2"; +$dbname = "test"; // Create connection -$conn = new mysqli($servername, $username, $password); +$conn = new mysqli($servername, $username, $password, $dbname); // Check connection +if ($conn->connect_error) { + echo('{"data":"error"}'); + return; +} if (isset($_POST['action'])) { @@ -15,10 +20,37 @@ if (isset($_POST['action'])) { case "getMovies": echo('{"data":[{"url":"./vid.mp4"}]}'); break; + case "getDbSize": + $query = "SELECT table_schema AS \"Database\", + ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS \"Size\" + FROM information_schema.TABLES + WHERE TABLE_SCHEMA='test' + GROUP BY table_schema;"; + $result = $conn->query($query); + + if ($result->num_rows == 1) { + $row = $result->fetch_assoc(); + + echo '{"data":"'.$row["Size"].'"}'; + } + + break; + case "storePic": + // Select file type + $imageFileType = strtolower(pathinfo("./lukas.png",PATHINFO_EXTENSION)); + // Convert to base64 + $image_base64 = base64_encode(file_get_contents("./lukas.png") ); + $image = 'data:image/'.$imageFileType.';base64,'.$image_base64; + // Insert record + $query = "insert into temppic(data) values('".$image."')"; + if ($conn->query($query) === TRUE) { + echo('{"data":"successfully created entry"}'); + } else { + echo('{"data":"'.$conn->error.'"}'); + } + break; } } else { - if ($conn->connect_error) { - echo('{"data":"error"}'); -// die("Connection failed: " . $conn->connect_error); - } + echo('{"data":"error"}'); } +$conn->close();