added php upload script

#8
David Zálešák 4 years ago
parent 7e8e87280c
commit 4db0ce0d9d

@ -31,8 +31,9 @@
</div> </div>
</aside> </aside>
<main> <main>
<form action="./upload.php" method="POST" class="hidden" id="form"> <form action="./upload.php" method="POST" class="hidden" id="form" enctype="multipart/form-data">
<input type="file" name="videoFile" id="videoFile"> <input type="file" name="videoFile" id="videoFile" accept="video/*">
<input type="text" name="xmlFile" hidden id="xmlFile">
</form> </form>
<video controls id="video" preload="auto" class="hidden"></video> <video controls id="video" preload="auto" class="hidden"></video>
<div class="video-controls hidden" id="video-controls"> <div class="video-controls hidden" id="video-controls">

@ -24,6 +24,7 @@ class Controller {
); );
} else { } else {
this.view.showAddVideo(); 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ů // Přidání listenerů
addEventListenersToVideoControls() { addEventListenersToVideoControls() {
const video = document.getElementById("video"); const video = document.getElementById("video");

@ -0,0 +1,66 @@
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$allowedExts = array("mp4", "mov", "wmv", "flv", "avi", "avchd", "webm", "mkv");
$extension = pathinfo($_FILES['videoFile']['name'], PATHINFO_EXTENSION);
if ((($_FILES["videoFile"]["type"] == "video/mp4")
|| ($_FILES["videoFile"]["type"] == "video/x-msvideo")
|| ($_FILES["videoFile"]["type"] == "video/mpeg")
|| ($_FILES["videoFile"]["type"] == "video/ogg")
|| ($_FILES["videoFile"]["type"] == "video/mp2t")
|| ($_FILES["videoFile"]["type"] == "video/webm")
|| ($_FILES["videoFile"]["type"] == "video/3gpp")
|| ($_FILES["videoFile"]["type"] == "video/x-matroska")
|| ($_FILES["videoFile"]["type"] == "video/3gpp2"))
&& ($_FILES["videoFile"]["size"] < 500000000)
&& in_array($extension, $allowedExts)
&& isset($_POST["xmlFile"])
) {
if ($_FILES["videoFile"]["error"] > 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;
}
?>
Loading…
Cancel
Save