HomeMediacenter/php/db/savemovietodb.php
2020-05-16 20:41:32 +02:00

43 lines
1.1 KiB
PHP
Executable File

<?php
$server = "172.17.0.2";
$user = "mediacenter";
$password = "w3xSBWWqvBFaLzmC";
$database = "mediacenter";
$link = new mysqli($server, $user, $password,$database);
if(mysqli_connect_errno())
{
echo "connecton failed... nr: ". mysqli_connect_errno(). " -- " . mysqli_connect_error();
}
$myobj->error = false;
$list = scandir("../../../Filme");
$myobj->data = array();
foreach ($list as $moviename) {
if (strpos($moviename, '.mp4') !== false) {
$name = substr($moviename, 0, -4);
$url = str_replace(" ","%20",$moviename);
$thumbnail = str_replace(" ","%20",str_replace(".mp4",".jpg",$moviename));
echo($name . "\n");
//check if movie already exists:
$query = "SELECT * FROM `movies` WHERE `name` = '$name'";
$result = mysqli_query($link,$query);
$resultnumber = $result->num_rows;
if ($resultnumber > 0) {
echo($name . "already exists!\n\n");
}else {
//save movies to db
$query = "INSERT INTO `movies` (`id`, `name`, `URL`, `thumbnail`) VALUES (NULL, '$name', '$url', '$thumbnail')";
$result = mysqli_query($link,$query);
}
}
}
?>