uploading and downloading videos in php with MYSQL

How to upload and download videos in php. The required scripts are given below.
videoupload1.php
<!DOCTYPE html>
<html>
<body>
<form action="videoupload1.php" method="post" enctype="multipart/form-data">
    Select video to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>
<?php
if(isset($_POST['submit']))
{
//$video=$_POST['fileToUpload'];
//$video=$_FILES["fileToUpload"]["name"];
$target_dir = "uploads/";
$target_file= $target_dir . basename($_FILES["fileToUpload"]["name"]);
$con=mysqli_connect("localhost","root","","kmbb");
if(!$con)
{
die("Unable to connect".mysqli_error());
}
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
 if($imageFileType != "mp4" && $imageFileType != "avi" && $imageFileType != "mov" && $imageFileType != "3gp" && $imageFileType != "mpeg")
{
    echo "File Format Not Suppoted";


if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$name= $_FILES["fileToUpload"]["name"];
mysqli_query($con,"insert into videotable1 values('','$name')");

echo 'video uploaded successfully';
}
mysqli_close($con);
}
?>
</body>

</html>
For  Displaying and downloading videos use the following script.

videoselect.php

<html>
<head>
<style type="text/css">
video
{
/*border:5px solid green;*/
 -webkit-border-image: url('h9.png') 30 round;
/*border-image-width: 20px;*/
border-radius:50%;
}
</style>
</head>
<body bgcolor="maroon">
<?php
$con=mysqli_connect("localhost","root","","kmbb");
if(!$con)
{
die("Unable to connect".mysql_error());
}
$q=mysqli_query($con,"select name from videotable1");
echo '<center><table border="" height="300" width="300" bgcolor="white">';
echo '<tr><th>VIDEOS</th></tr>';
if (mysqli_num_rows($q) > 0)
while($r=mysqli_fetch_assoc($q))
{
echo "<tr>";
echo '<td align="center">'.'<video src="uploads/'.$r['name'].'" height="100" width="300" type="video" controls></video></td>';

echo "</tr>"; 
}
echo '</table></center>';
mysqli_close($con);
?>
</body>
</html>

Comments

Popular posts from this blog

PHP AND UI TRAINING AND DEVELOPMENT