Upload video & Approve video using the form in PHP / How can we upload video in PHP?

Hello Friends, In this blog post, I will show you the upload video functionality through the user registration form and how the admin approves video before it is available for the users.

Using this blog we are going to show How can we upload videos in PHP? How can I upload audio and video in PHP? How do you upload a video to SQL DataBase? How can I upload my video? Video uploading in PHP source code…

…How to display video in PHP from the database, Multiple video upload in PHP, Upload and display video using PHP, MySQL, Upload video in PHP, Upload video in PHP source code download, How to insert video in MySQL database, Php video upload with thumbnail.

We have divided this functionality into two major modules, one is the user module and another is the admin module.

A user will upload a video and after the admin approves, he can see all the approved videos till now along with his own video.

videoapproval2

When a user will upload a video it will reach the admin panel and when the admin will approve the video then it will go to the general view and will be visible to each user.

So this is simply video submission and approval functionality.


So how would you make this functionality of upload video and approve video?

This is a very simple application you just need to follow the step by step procedure given below.

before starting the actual procedure I just want to let you know the software which we used for making this functionality of upload video and approve the video.


Software used:

NetBeans IDE

XAMPP Server

Though you can use any IDE which you are familiar with for developing this functionality.


First, Crate one SQL database name as debuts in our case and then create two tables, see the codes for the same below.

[code]

— phpMyAdmin SQL Dump
— version 4.1.12
— http://www.phpmyadmin.net

— Host: 127.0.0.1
— Generation Time: Nov 15, 2018 at 12:17 PM
— Server version: 5.6.16
— PHP Version: 5.5.11

SET SQL_MODE = “NO_AUTO_VALUE_ON_ZERO”;
SET time_zone = “+00:00″;

/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;
/*!40101 SET @[email protected]@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;


— Database: `dbtuts`

— ——————————————————–


— Table structure for table `admin`

CREATE TABLE IF NOT EXISTS `admin` (
`id` varchar(20) NOT NULL,
`username` varchar(25) NOT NULL,
`password` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


— Dumping data for table `admin`

INSERT INTO `admin` (`id`, `username`, `password`) VALUES
(”, ‘anurag’, ‘123’);

— ——————————————————–


— Table structure for table `tbl_uploads`

CREATE TABLE IF NOT EXISTS `tbl_uploads` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`email` varchar(20) NOT NULL,
`password` varchar(20) NOT NULL,
`mobile` int(20) NOT NULL,
`file` varchar(100) NOT NULL,
`type` varchar(30) NOT NULL,
`size` int(11) NOT NULL,
`status` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=43 ;


— Dumping data for table `tbl_uploads`

INSERT INTO `tbl_uploads` (`id`, `name`, `email`, `password`, `mobile`, `file`, `type`, `size`, `status`) VALUES
(35, ‘anurag’, ‘[email protected]’, ‘123’, 123, ‘72752-samplevideo.mp4’, ‘video/mp4’, 2058, ‘approved’),

/*!40101 SET [email protected]_CHARACTER_SET_CLIENT */;
/*!40101 SET [email protected]_CHARACTER_SET_RESULTS */;
/*!40101 SET [email protected]_COLLATION_CONNECTION */;

[/code]

Create a project name say video file upload.

then create the file structure as given below.

videoapproval3

Once you create all the files then just copy and paste the code given below.


index.php

[code]

<?PHP
include_once ‘dbconfig.php’;
?>
<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>User Registration Form</title>
<link rel=”stylesheet” href=”style.css” type=”text/css” />
</head>
<body>
<div id=”headregis”>
<label id=”head”>User Registration Form</label>
</div>
<div class=”container”>
<div class=”main”>
<form action=”upload.php” method=”Post” enctype=”multipart/form-data” id=”form”>
<label>Enter Name:</label> <input type=”text” name =”name” id=”nme”/></br>
<label>Enter password:</label><input type =”password” name=”password” id =”pwd”/></br>
<label>Enter Email Id:</label> <input type =”email” name=”email” id=”mail”/></br>

<label>Enter Mobile No.:</label><input type=”number” name=”mobile” id=”mobno”/></br>
<label>Upload Your Video</label>

<input type=”file” name=”file” />
<button type=”submit” name=”btn-upload”>upload</button>
</form>
<br /><br /><label>Try to upload any files(PDF, DOC, EXE, VIDEO, MP3, ZIP,etc…)</label>

</div>
</div>

</body>
</html>

[/code]


login.php

[code]

<!DOCTYPE html>
<?php session_start(); ?>
<?php
if (isset($_SESSION[‘login_user’])) { // if already login
header(“location: view.php”); // send to home page
exit;
}
?>

<html>
<head>
<title>
</title>
<link href=”style.css” rel=”stylesheet” type=”text/css”/>
</head>
<body>

<div id=”userform”>
<h1 style=”text-align: center;”>User Login </h1>
<form action=”” method=”GET” id=”form”/>
<label>UserName:</label>
<input type =”text” name=”username”/></br>
<label>Password:</label>
<input type=”password” name=”password”/>
<input type=”submit” name=”sbt”/></form>
<a href=”index.php”>New User Register Here…</a>
</div>

</br>
<div id=”loginform”>
<h1 style=”text-align: center;”>Admin Login</h1>
<form action=”” method=”GET” id=”form1″/>
<label>UserName:</label>
<input type =”text” name=”username”/></br>
<label>Password:</label>
<input type=”password” name=”password”/>
<input type=”submit” name=”smbt”/></form>
</div>

</body>
</html>
<?php
if (isset($_GET[‘sbt’])) {
$connection = mysql_connect(“localhost”, “root”, “”);
$db = mysql_select_db(“dbtuts”, $connection);

$user = $_GET[‘username’];
$pass = $_GET[‘password’];
$_SESSION[‘login_user’] = $user;
$query = mysql_query(“select * from tbl_uploads where ‘$user’=name AND ‘$pass’=password”, $connection);
$rows = mysql_num_rows($query);

if ($rows == 1) {

header(“location: view.php”); // Redirection To Other Page
} else {

echo “<script type=’text/javascript’>alert(‘Username or Password is invalid!’)</script>”;
}
}
?>

<?php
if (isset($_GET[‘success’])) {
?>
<label>File Uploaded Successfully please make login once with your userid and password to view your files…</label>
<?php
} else if (isset($_GET[‘fail’])) {
?>
<label>Problem While File Uploading !</label>
<?php
}
?>

<?php
if (isset($_GET[‘smbt’])) {
$connection = mysql_connect(“localhost”, “root”, “”);
$db = mysql_select_db(“dbtuts”, $connection);
$user = $_GET[‘username’];
$pass = $_GET[‘password’];
$query = mysql_query(“select * from admin where ‘$user’=username AND ‘$pass’=password”, $connection);
$rows = mysql_num_rows($query);

if ($rows == 1) {

header(“location: adminpanel.php”); // Redirection To Other Page
} else {

echo “<script type=’text/javascript’>alert(‘Username or Password is invalid!’)</script>”;
}
}
?>

[/code]


upload.php

[code]

<?php

include_once ‘dbconfig.php’;
if (isset($_POST[‘btn-upload’])) {
$name = $_POST[‘name’];
$password = $_POST[‘password’];
$email = $_POST[’email’];

$mobile = $_POST[‘mobile’];

$file = rand(1000, 100000) . “-” . $_FILES[‘file’][‘name’];
$file_loc = $_FILES[‘file’][‘tmp_name’];
$file_size = $_FILES[‘file’][‘size’];
$file_type = $_FILES[‘file’][‘type’];
$folder = “uploads/”;

// new file size in KB
$new_size = $file_size / 1024;
// new file size in KB
// make file name in lower case
$new_file_name = strtolower($file);
// make file name in lower case

$final_file = str_replace(‘ ‘, ‘-‘, $new_file_name);

if (move_uploaded_file($file_loc, $folder . $final_file)) {
//$sql=”INSERT INTO tbl_uploads(file,type,size) VALUES(‘$final_file’,’$file_type’,’$new_size’)”;
//mysql_query($sql);
$sql = “insert into tbl_uploads(name,password,email,mobile,file,type,size,status) values(‘$name’,’$password’,’$email’,’$mobile’,’$final_file’,’$file_type’,’$new_size’,’pending’)”;
mysql_query($sql);
?>
<script>
alert(‘successfully uploaded’);
window.location.href = ‘login.php?success’;
</script>
<?php

} else {
?>
<script>
alert(‘error while uploading file’);
window.location.href = ‘login.php?fail’;
</script>
<?php

}
}
?>

[/code]


view.php

[code]

<?php
include_once ‘dbconfig.php’;
?>
<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>File Uploading With PHP and MySql</title>
<link rel=”stylesheet” href=”style.css” type=”text/css” />
</head>
<body>
<div id=”header”>
<label id=”vtitle”>File Uploading With PHP and MySql</label>
<label id=”lgout”><a href=”logout.php”>Logout</a></label>
</div>
<div id=”tbbody”>
<table width=”100%” border=”1″ id=”tb1″>
<tr>
<th colspan=”4″>your uploads…<label><a href=”index.php”>upload new files…</a></label></th>
</tr>
<tr>
<td>File Name</td>
<td>File Type</td>
<td>File Size(KB)</td>
<td>View</td>
</tr>
<?php
$sql = “SELECT * FROM tbl_uploads where status=’approved'”;
$result_set = mysql_query($sql);

while ($row = mysql_fetch_array($result_set)) {
?>
<tr>
<td>
<video width=”320″ height=”240″ controls>
<source src=”uploads/<?php echo $row[‘file’] ?>” type=”video/mp4″>
Your browser does not support the <code>video</code> tag.
</video>

</td>
<td><?php echo $row[‘type’] ?></td>
<td><?php echo $row[‘size’] ?></td>
<td><a href=”uploads/<?php echo $row[‘file’] ?>” target=”_blank”>view file</a></td>
</tr>
<?php
}
?>
</table>

</div>
</body>
</html>

[/code]


Conclusion:

We have gone through How can we upload video in PHP? How can I upload audio and video in PHP? How do you upload a video to SQL DataBase? How can I upload my video? Video uploading in PHP source code, How to display video in PHP from the database, Multiple video upload in PHP, Upload and display video using PHP MySQL, Upload video in PHP w3schools, Upload video in PHP source code download, How to insert video in MySQL database, Php video upload with thumbnail.

In case of any queries, you can write to us at [email protected] we will get back to you ASAP.

Hope! you would have enjoyed this post to upload video and approve video using the form.

Please feel free to give your important feedbacks in the comment section below.

Have a great time! Sayonara!

Anurag

I am a blogger by passion, a software engineer by profession, a singer by consideration and rest of things that I do is for my destination.