Friday, September 7, 2012

Simple Video Gallery in php



Simple Video Gallery in php 


This tutorial is created to upload your videos in to a folder called "video" and also send ID,Date Added,Name of video and video description in to a MySQL table called "myvideo" in my_database Where you can select the video and view it.
Create following upload scripts file first

Video Upload


upload your videos
Title
Select file
Video Description

<html>
 <head>
 <title>Video Upload</title>
</head>
<body>
<center><h2>Video Upload </h2></center>
<form action="vd3.php" method="post" enctype="multipart/form-data" name="form1" id="form1" > <tr><td>
<table align="center">
<tr><td colspan=2><hr></hr></td></tr>
<tr> <td><strong>upload your videos </strong></td> </tr>
<tr><td>Title</td></tr>
<tr><td><input type="text" name="txtName"></td></tr>
 <tr> <td>Select file <input name="ufile" type="file" id="ufile" size="50" /></td> </tr>
<tr><td>Video Description</br><textarea cols="40" rows="5" name="details">
</textarea></td></tr>
<tr><td align="center"><input type="submit" name="Submit" value="Upload" /></td> </tr>
</form>
<tr><td colspan=2><hr></hr></td></tr>
</table>
</body>
</html>

Then create vd3.php which upload file in to upload folder and write details in to MySQL table

<?php
$path1= "video/".$_FILES['ufile']['name'];

$date = date("y/m/d");
$time = date("g:i a");
$file_name = $_FILES['ufile']['name'];
if($file !=none)
{
 if(copy($_FILES['ufile']['tmp_name'], $path1))
{
 mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("my_database");
$strSQL = "INSERT INTO myvideo";
 $strSQL .="(date,time,Name,file,details) VALUES ('$date','$time','".$_POST["txtName"]."','$file_name','".$_POST["details"]."')";

mysql_query($strSQL); echo "<center>Uploaded To videos</center> ";
  mysql_close();
 }
}
 else { echo "ERROR.....";
}
?>

Your uploaded files could be viewed by using the bellow php file

Video Gallery

ID
Date Added
Name Of Video
Open File
Video Description
1 12/09/07 Butter Production Butter Production steps 


<?php
 $dbHost = 'localhost';
$dbUser = 'root';
 $dbPass = '';
$dbName = 'my_database';
$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());
?>
<html>
 <head>
<title></title>
</head>
<body>
 <h2><font color="#54164e"><center>Video Gallery</font></center></h2>
<table align="center" bgcolor="#9a7608" cellpadding="10" cellspacing="3">
<tr bgcolor="#ffffff">
<th> <center> ID </center>
</th> <th> <center>Date Added</center> </th>
<th> <center>Name Of Video</center> </th>
<th> <center> Open File </center> </th>
 <th> <center> Video Description</center> </th>
</tr>

<?php
 $query = "SELECT * FROM myvideo";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)){
 ?>
<form name="form" method="post">
<tr bgcolor="#ffffff">
<td><?php echo $row["ID"];?></td>
 <td><?php echo $row["date"];?></td>
<td><?php echo $row["Name"];?></td>
<th><a href="video/<?php echo $row['file'];?>"><img src="vd.png"></a></th>
<td><?php echo $row["details"];?> </td></tr>
 <?php
}
?>

</table>
</form>
</body>
</html>

No comments:

Post a Comment