diff --git a/js/controller.js b/js/controller.js
index a5a193c..a7f28d5 100644
--- a/js/controller.js
+++ b/js/controller.js
@@ -24,6 +24,7 @@ class Controller {
);
} else {
this.view.showAddVideo();
+ this.addEventListenersToAddVideo();
}
}
@@ -37,6 +38,13 @@ class Controller {
);
}
+ addEventListenersToAddVideo() {
+ let form = document.getElementById("form");
+ form.addEventListener("submit", function () {
+ document.getElementById("xmlFile").value = this.view.editor.getValue();
+ }.bind(this));
+ }
+
// Přidání listenerů
addEventListenersToVideoControls() {
const video = document.getElementById("video");
diff --git a/upload.php b/upload.php
new file mode 100644
index 0000000..415084c
--- /dev/null
+++ b/upload.php
@@ -0,0 +1,66 @@
+ 0) {
+ redirect("?e='" . $_FILES["videoFile"]["error"] . "'");
+ } else {
+ do {
+ $generatedFileName = generateRandomString();
+ } while (file_exists("videos/" . $generatedFileName . "." . $extension));
+
+ move_uploaded_file(
+ $_FILES["videoFile"]["tmp_name"],
+ "videos/R-" .
+ $generatedFileName . "." . $extension
+ );
+ writeToFile("videos/" . $generatedFileName . ".xml", $_POST["xmlFile"]);
+ shell_exec("./transcode.sh > /dev/null 2>&1 &");
+ redirect("?v=" . $generatedFileName);
+ }
+ } else {
+ redirect("?e='invalid file'");
+ }
+} else {
+ redirect();
+}
+
+function writeToFile($file, $xml) {
+ $myfile = fopen($file, "w") or die("Unable to open file!");
+ $txt = "John Doe\n";
+ fwrite($myfile, $xml);
+ fclose($myfile);
+}
+
+function redirect($videoID = null)
+{
+ header("Location: index.html" . $videoID);
+ die();
+}
+
+function generateRandomString($length = 4)
+{
+ $characters = 'abcdefghijklmnopqrstuvwxyz';
+ $charactersLength = strlen($characters);
+ $randomString = '';
+ for ($i = 0; $i < $length; $i++) {
+ $randomString .= $characters[rand(0, $charactersLength - 1)];
+ }
+ return $randomString;
+}
+?>
\ No newline at end of file