You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.2 KiB
PHP

<?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;
}
?>