Vedio upload in database and watch in PHP

In this article upload vedio in DB and watch vedio by PHP coding.
First of all create a database in phpmyadmin. In this example db name is 'demo' and table name 'audio'.
Table audio have three coloum that is ID, name , url.

Now create html ....

<?php
@mysql_connect("localhost","root","") or die(mysql_error());
@mysql_select_db("demo");

  if(isset($_POST['submit']))
 {
  $name = $_FILES['file']['name'];
  $temp = $_FILES['file']['tmp_name'];
  
  //move_uploaded_file($temp, 'uploaded/' . $_FILES['file']['name']);
  move_uploaded_file($_FILES["file"]["tmp_name"], "uploaded/" . $_FILES["file"]["name"]);
  $url = "http://localhost/demo/vedio/uploaded/$name";
  mysql_query("INSERT INTO audio (name, url) VALUES ('$name', '$url')");
 }
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Vedio upload</title>
</head>
<body>
<a href="vedioupload.php">All Vedios</a><br/><br/>
<form action="index.php" method="POST" enctype="multipart/form-data">
        <input type="file" name="file" />    
  <input type="submit" value="Upload!" name="submit" />
</form>
<?php
if(isset($_POST['submit']))
 {
  echo "<br>" . $name . " has been uploaded!";

 }
?>
</body>

</html>

(index.php) This is index.php file and using this upload vedio in db.
One folder create which name is 'uploaded'. When any vedio upload in db, also upload in this folder. 

Here is code of index.php file...

<?php
@mysql_connect("localhost", "root", "") or die(@mysql_error());
@mysql_select_db("demo");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Vedio upload</title>
</head>
<body>

<?php
 $query = mysql_query("select * from audio");
 while($row = mysql_fetch_assoc($query))
 {
  $id = $row['id'];
  $name = $row['name'];
  
  echo "<a href='watch.php?id=$id'>$name</a><br>";
 }
?>
</body>

</html>






After this click All Vedios link and redirect vedioupload.php file and show all vedio...

Here is code vedioupload.php file...

<?php
@mysql_connect("localhost","root","") or die(mysql_error());
@mysql_select_db("demo");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Vedio upload</title>
</head>
<body>

<?php

  if(isset($_GET['id']))
 {
  $id = $_GET['id'];
  $query = mysql_query("select * from audio where id='$id'");
  while($row = mysql_fetch_assoc($query))
  {
   $name = $row['name'];
   $url = $row['url'];
  }
  
  echo "You are watching ".$name."<br>"; 
  // echo "<embed src='$url' width='360' height='215'></embed>";
  echo "<iframe src='$url'></iframe>";
 }
 else 
 {
  echo "Error!";
 }
?>
</body>

</html>







When Click any vedio redirect to watch.php file...







Labels: