0

I need to create a code to upload videos for a university subject and then connect it by mysql using some virtual box dockers but there is a problem with the php code and i cannot find where the error is. (500 HTTP ERROR). There is no problem with the mysql connection or form data, is something related with the php code, and the other pages still work. I'm new on this and it is making me crazy because i cannot keep doing the other part of the project because it is related to this one.

 

<?php

$target_dir = "./videosSubidos/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$uploadFinal =1;
$videosFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if videos file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getvideosize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "El archivo es un video- " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "El archivo no es un video.";
        $uploadOk = 0;
    }
}
// Check if file already exists
if (file_exists($target_file)) {
    echo "Lo sentimos, ese video ya existe.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 2000000) {
    echo "El vídeo es demasiado grande.";
    $uploadOk = 0;
}
// Allow certain file formats
if($videoFileType != "mov" && $videoFileType != "MOV" && $videoFileType != "mp4" && $videoFileType != "mkv" && $videoFileType != "ogg" 
&& $videoFileType != "flv" && $videoFileType != "mpeg" && $videoFileType != "MP4" && $videoFileType != "avi"  && $videoFileType != "wmv" && $videoFileType != "webm"  ) {
    echo "Lo siento, esa extensión no está dentro de las permitidas";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Lo sentimos, el video no fue subido.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "El video ". basename( $_FILES["fileToUpload"]["name"]). " se ha subido.";
        $uploadFinal == 1;
    } else {
        echo "Lo sentimos, ha habido un error subiendo tu video.";
        $uploadFinal == 0;

    }
}

if ($uploadFinal == 1){
    echo "Realizando conexión con base de datos";
    $conn = new mysqli("10.0.2.15", "root", "sarapo", "videos");  

    /* verificar la conexión */

    if (!$conn) {

      die("Fallo en la conexión: " . mysqli_connect_error());
  } echo "Conexión exitosa";

  $queryREC= "INSERT INTO subir (nombre, tipo) VALUES ( '$_FILES["fileToUpload"]["name"]', '$videosFileType')";
  mysqli_query($conn, $queryREC);

  /* cerrar la conexión */
  mysqli_close($conn);*/


}
?>




<!DOCTYPE html>
<html>
<body>

<form action ="<?php echo $_SERVER['PHP_SELF']?>" method="post" enctype='multipart/form-data'>
    Select video to upload:
    <br><br><input type="file" name="archivo a subir" id="fileToUpload"><br><br>
    <br><br><input type="submit" value="Subir" name="submit"><br><br>
</form>

</body>
</html>
sxrisw
  • 1
  • 1

0 Answers0