add php upload form

This commit is contained in:
Carneiro 2024-08-01 17:31:21 -03:00
parent 195e88a079
commit 368072837e
2 changed files with 76 additions and 12 deletions

18
_includes/formularios/envAula.html Normal file → Executable file
View File

@ -1,20 +1,12 @@
<div class="envArquivo" style="height: 100vh; width: 100vw;"> <div class="envArquivo" style="height: 100vh; width: 100vw;">
<h1> Enviar Aula</h1> <h1> Enviar Aula</h1>
<form action="submit_class.php" method="post"> <form action="upload.php" method="post" enctype="multipart/form-data">
<!-- Nome da Aula --> <!-- Nome da Aula -->
<div class="field"> <div class="field">
<label class="label" for="class_name">Nome da Aula</label> <label class="label" for="class_name">Nome da Aula</label>
<div class="control"> <div class="control">
<input class="input" type="text" id="class_name" name="class_name" required> <input class="input" type="text" id="videoTitle" name="videoTitle" required>
</div>
</div>
<!-- Autor -->
<div class="field">
<label class="label" for="author">Autor</label>
<div class="control">
<input class="input" type="text" id="author" name="author" required>
</div> </div>
</div> </div>
@ -48,10 +40,14 @@
</div> </div>
</div> </div>
<div class="field">
<input type="file" name="fileToUpload" id="fileToUpload">
</div>
<!-- Botão de Enviar --> <!-- Botão de Enviar -->
<div class="field"> <div class="field">
<div class="control"> <div class="control">
<button class="button is-primary" type="submit">Enviar</button> <button class="button is-primary" name="submit" type="submit">Enviar</button>
</div> </div>
</div> </div>
</form> </form>

68
upload.php Executable file
View File

@ -0,0 +1,68 @@
<?php
$username = $_SERVER['PHP_AUTH_USER'];
$target_dir = "/var/www/html/aliceclass_videos/" . $username;
# check if user dir exists
if (!file_exists($target_dir)) {
# if not, create it
if (mkdir($target_dir, 0775, true)) {
// echo "Directory created successfully.";
}
if (mkdir($target_dir . "/src", 0775, true)) {
// echo "Directory created successfully.";
}
if (mkdir($target_dir . "/dest", 0775, true)) {
// echo "Directory created successfully.";
}
}
$fileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$uploadOk = 1;
// if ($fileType != '.mkv') {
// echo "Apenas arquivos .mkv são aceitos. ";
// $uploadOk = 0;
// }
echo $_POST["videoTitle"];
$ext = ".mkv";
$brute_file = $target_dir . "/src/" . $_POST["videoTitle"] . $ext;
$target_file = $target_dir . "/dest/" . $_POST["videoTitle"] . '.mp4';
echo $brute_file;
echo $target_file;
// return;
// Check if file already exists
if (file_exists($brute_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
if ($uploadOk == 1) {
if (!move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $brute_file)) {
echo "Houve um problema com o upload do arquivo.";
return;
}
}
// return;
// ./script.sh "TESTE" "TESTAO" "/home/carneiro/Introdução ao LMMS.mkv" "AULATESTE" /home/carneiro/teste.mp4
echo "The file ". htmlspecialchars(basename( $_FILES["videoTitle"]["name"])). " has been uploaded.";
$SCRIPT_PATH = "/var/www/src/AliceClass/script/script.sh";
$AUTHOR = $username;
$NAME = $_POST["videoTitle"];
$INPUT = $brute_file;
$OUTPUT = $target_file;
$cmd = sprintf('%s "%s" "%s" "%s" "%s" "%s"', $SCRIPT_PATH, $NAME, $AUTHOR, $INPUT, 'aulateste', $OUTPUT);
// echo $cmd;
// exit;
$output = shell_exec($cmd);
?>