Here I can upload videos successfully into database and videos are saving in appropriate folder named "uploaded". As I mentioned in question, once after uploading the video, if I refresh the browser the previously uploaded video is going saving in my database. Another question is, I cannot see or watch the videos. I request you people to give me solutions to solve these problems. Below I am posting my code:
myvideo.php:
<div class="content">
<div class="card">
<div class="header" id="stand-fix" style="border-bottom: 1px solid #E1E1E1;">
<?php
if(isset($_POST['submit']))
{
// $conn = mysqli_connect("localhost", "root", "", "videos") or die(mysqli_error());
$name = (isset($_FILES['file']['name']) ? $_FILES['file']['name'] : '');
$temp = (isset($_FILES['file']['tmp_name']) ? $_FILES['file']['tmp_name'] : '');
move_uploaded_file($temp, "uploaded/".$name);
$url = "http://localhost/xampp/htdocs/VS/uploaded/$name";
mysqli_query($database, "INSERT INTO video VALUE ('','$name','$url')");
}
?>
<form action="myvideo.php" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-7">
<h4 class="title">My Videos</h4>
</div>
<div class="col-md-3">
<input type="file" name="file" class="btn btn-primary" style="font-size: 15px;"><br />
</div>
<div class="col-md-2">
<input type="submit" name="submit" class="btn btn-primary pull-right" style="font-size: 15px;" value="Upload">
</div>
</div>
</form>
<?php
if(isset($_POST['submit']))
{
echo '<script language="javascript">';
echo 'alert("Your video has been successfully uploaded.")';
echo "window.location.href='dashboard.php'";
echo '</script>';
}
?>
<hr width="50%">
</div>
<div class="content" style="height: 30em; direction: ltr; overflow: auto;">
<div class="row" style="margin-left:4em;" style="direction: rtl;">
<?php
$database = mysqli_connect("localhost", "root", "", "videos") or die(mysqli_error());
$query = mysqli_query($database, "SELECT * FROM video");
while($row=mysqli_fetch_assoc($query))
{
$id = $row['id'];
$name = $row['name'];
$url = $row['url'];
echo "<p style='margin:0.5em;'><a href='watch1.php?id=$id' style='color:red;'>$id $name</a></p><br />";
echo "<embed src='.$id.$url.'><video width='200' height='200' controls></video></embed>";
}
?>
</div>
</div>
</div>
</div>
watch.php
<?php
$conn = mysqli_connect("localhost", "root", "", "videos") or die(mysqli_error());
if(isset($_GET['id']))
{
$id = $_GET['id'];
$query = mysqli_query($conn, "SELECT * FROM video WHERE id='$id'");
while($row=mysqli_fetch_assoc($query))
{
$name = $row['name'];
$url = $row['url'];
}
echo "<p style='font-size:20px;'><center>You are watching ".$name."</center></p><br /><embed src='.$url.'><video width='600' height='400' controls></video></embed>";
}
else
{
echo "Error!";
}
?>
Bookmarks