Home >>MySQL Tutorial >Upload and Display Video in PHP
//create a database demo CREATE DATABASE `demo`; USE demo; //create a table textarea CREATE TABLE `video` ( `v_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `video_name` varchar(255) not null )
<?php error_reporting(1); $con=mysql_connect("localhost","root",""); mysql_select_db("demo",$con); extract($_POST); $target_dir = "test_upload/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); if($upd) { $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); if($imageFileType != "mp4" && $imageFileType != "avi" && $imageFileType != "mov" && $imageFileType != "3gp" && $imageFileType != "mpeg") { echo "File Format Not Suppoted"; } else { $video_path=$_FILES['fileToUpload']['name']; mysql_query("insert into video(video_name) values('$video_path')"); move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$target_file); echo "uploaded "; } } //display all uploaded video if($disp) { $query=mysql_query("select * from video"); while($all_video=mysql_fetch_array($query)) { ?> <video width="300" height="200" controls> <source src="test_upload/<?php echo $all_video['video_name']; ?>" type="video/mp4"> </video> <?php } } ?>
<form method="post" enctype="multipart/form-data"> <table border="1" style="padding:10px"> <tr> <Td>Upload Video</td></tr> <Tr><td><input type="file" name="fileToUpload"/></td></tr> <tr><td> <input type="submit" value="Uplaod Video" name="upd"/> <input type="submit" value="Display Video" name="disp"/> </td></tr> </table> </form>