Upload video files Images using PHP mysql

Upload video files Images using PHP mysql

In this Post We Will Explain About is Upload video files Images using PHP mysql With Example and Demo.Welcome on Pakainfo.com, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to Insert Videos into a MySQL Database Using PHPExample

In this post we will show you Best way to implement how to upload videos to directory in php using mysql database, hear for Upload And Display Video Using PHP MySQLwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Include External Scripts

<link rel="stylesheet" type="text/css" href="css/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="css/jquery.timepicker.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/jquery-1.11.1.min.js"></script>
<script src='js/jquery-ui.min.js'></script>
<script src="js/jquery.timepicker.min.js"></script>

Success Thankyou Message

<?php 
	if(isset($_GET['message'])) {
?>
<div class="text-center isa_success">
	<h2>Thanks for your time.</h2>
</div>
<?php
	}
?>

index.php

      
	  <form name="basicform" enctype="multipart/form-data" id="basicform" method="post" action="data_submit.php">
        
        <div id="sf1" class="frm">
		
		<section class="part_1">

			<div class="applicant_information mt_bottom">
				<h3 class="title_text">Live clients contact information</h3>
				<fieldset class="light_bg">
						<table>
							<tbody>
								<tr>
									<td><label>Name:</label></td>
									<td><input type="text" class="form-group" name="empname" id="empname" value="" /></td>
								</tr>
								<tr>
									<td><label>Address:</label></td>
									<td><input type="text" class="form-group" name="resaddress" id="resaddress" value="" /></td>
								</tr>
								<tr>
									<td><label>Phone Number:</label></td>
									<td><input type="text" class="form-group" name="phonumber" id="phonumber" value="" /></td>
								</tr>
								<tr>
									<td><label>Email:</label></td>
									<td><input type="text" class="form-group" name="email" id="email" value="" /></td>
								</tr>
							     <tr>
									<td><label>Website Name</label></td>
									<td><input type="text" class="form-group" name="myweb" id="myweb" value="" /></td>
								</tr>
								<tr>
									<td><label>img_gallery</label></td>
									<td><input type="text" class="form-group" name="gallery" id="gallery" value="" /></td>
								</tr>

								
							</tbody>
						</table>
					
				</fieldset>				
			</div>
			<div class="event_information mt_bottom">
				<h3 class="title_text">Please provide the following support material</h3>
				<fieldset class="light_bg">
				
						<table>
							<tbody>
								<tr>
									<td colspan="3"><label>CV</label></td>
									<td><input type="file" class="form-group" name="livecvfile" id="livecvfile" value="" />(no more than 2 x A4 pages)</td>
								</tr>
								<tr>
									<td colspan="3"><label>Media</label></td>
									<td><input type="file" class="form-group" name="livevideo" id="livevideo" value="" />(MP4 under 50 MB)</td>
								</tr>
							</tbody>
						</table>
				
				</fieldset>	
			</div>
			<div class="event_information mt_bottom">
				<h3 class="title_text">Employer Descriptions</h3>
				<fieldset class="light_bg">
				
						<table>
							<tbody>
								<tr>
									<td><textarea name="longdesc" id="longdesc"></textarea></td>
								</tr>
							</tbody>
						</table>
				
				</fieldset>	
			</div>
			<div class="acceptance_application mt_bottom">			
				<div class="light_bg">
					<span><b>I certify that, to the best of my knowledge the statements in this application are true. </b></span>
					<table>
						<tbody>
							<tr>
								<td><label>Full name</label></td>
								<td colspan="3"><input type="text" class="form-group" name="firstname" id="firstname" value="" /></td>
							</tr>
							<tr>
								<td><label>Signature</label></td>
								<td colspan="3"><input type="file" class="form-group" name="basicsign" id="basicsign" value="" /></td>
							</tr>
							<tr>
								<td><label>Date</label></td>
								<td colspan="3"><input type="text" class="form-group" name="crdate" id="crdate" value="" /></td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
		</section>
            <div class="foot_btn">
				<div class="text-right light_bg">
				<img src="spinner.gif" alt="" id="loader" style="display: none">
                <button class="open3 btn_light" type="submit">Submit </button> 
              </div>
            </div>
      </form>

data_submit.php

<?php
require 'class.phpmailer.php';

$empname = $_POST['empname'];
$resaddress = $_POST['resaddress'];
$phonumber = $_POST['phonumber'];
$email = $_POST['email'];
$myweb = $_POST['myweb'];
$gallery = $_POST['gallery'];
$firstname = $_POST['firstname'];
//$basicsign = $_POST['basicsign'];
$crdate = $_POST['crdate'];
$longdesc = $_POST['longdesc'];

$path="https://www.pakainfo.com/my_contact/dvd_data/";


$video_link = $_FILES["livevideo"]["name"];
$data_link = $_FILES["livecvfile"]["name"];
$sign_link = $_FILES["basicsign"]["name"];



$check_extentions = array("pdf", "jpg", "jpeg", "mp4");
$extension = pathinfo($_FILES['livevideo']['name'], PATHINFO_EXTENSION);
																	                    
if ((($_FILES["livevideo"]["type"] == "video/mp4"))&& ($_FILES["livevideo"]["size"] < 50000000)
 && in_array($extension, $check_extentions))
  {
  if ($_FILES["livevideo"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["livevideo"]["error"] . "<br />";
    }
  else
    {
   // echo "Upload: " . $_FILES["livevideo"]["name"] . "<br />";
    //echo "Type: " . $_FILES["livevideo"]["type"] . "<br />";
    //echo "Size: " . ($_FILES["livevideo"]["size"] / 1024) . " Kb<br />";
    //echo "Temp file: " . $_FILES["livevideo"]["tmp_name"] . "<br />";
		$temp_media = explode(".", $_FILES["livevideo"]["name"]);
	    $new_tempfilename = date("Ymd").round(microtime(true)) . '.' . end($temp_media);
    if (file_exists("dvd_data/dvd_data/" . $new_tempfilename))
      {
     // echo $_FILES["livevideo"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["livevideo"]["tmp_name"],
      "dvd_data/dvd_data/" . $new_tempfilename);
     // echo "Stored in: " . "dvd_data/" . $_FILES["livevideo"]["name"];
      }
    }
  }
else
{
	echo "Invalid file/MP4 under 50 MB";
}


$my_extension = pathinfo($_FILES['livecvfile']['name'], PATHINFO_EXTENSION);

if ((($_FILES["livecvfile"]["type"] == "image/jpeg") || ($_FILES["livecvfile"]["type"] == '"application/pdf"'))&& ($_FILES["livecvfile"]["size"] < 6000000) && in_array($my_extension, $check_extentions))
  {
  if ($_FILES["livecvfile"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["livecvfile"]["error"] . "<br />";
    }
  else
    {
	$temp_cv = explode(".", $_FILES["livecvfile"]["name"]);
	$new_cvfilename = date("Ymd").round(microtime(true)) . '.' . end($temp_cv);
    if (file_exists("dvd_data/Documents/" . $new_cvfilename))
      {
        //echo $_FILES["livecvfile"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["livecvfile"]["tmp_name"],"dvd_data/Documents/" . $new_cvfilename);
      //echo "Stored in: " . "dvd_data/Documents/" . $_FILES["livecvfile"]["name"];
      }
    }
  }
else
{
	echo "Invalid file/JPG or PDF under 6MB";
}


$my_extension = pathinfo($_FILES['basicsign']['name'], PATHINFO_EXTENSION);

if ((($_FILES["basicsign"]["type"] == "image/jpeg") || ($_FILES["basicsign"]["type"] == '"application/pdf"'))&& ($_FILES["basicsign"]["size"] < 6000000) && in_array($my_extension, $check_extentions))
  {
  if ($_FILES["basicsign"]["error"] > 0)
    {
      //echo "Return Code: " . $_FILES["basicsign"]["error"] . "<br />";
    }
  else
    {
	$temp_sign = explode(".", $_FILES["basicsign"]["name"]);
	$new_signfilename = date("Ymd").round(microtime(true)) . '.' . end($temp_sign);
    if (file_exists("dvd_data/sign/" . $new_signfilename))
      {
        //echo $_FILES["basicsign"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["basicsign"]["tmp_name"],"dvd_data/sign/" . $new_signfilename);
      //echo "Stored in: " . "dvd_data/Documents/" . $_FILES["basicsign"]["name"];
      }
    }
  }
else
{
	echo "Invalid file/JPG or PDF under 6MB";
}


$to = "[email protected]";
//$to = "[email protected]";
//$to2 = "[email protected]";
//$to2 = "[email protected]";
$subject = "live24u/w3free Inquiry form";

	$message=" ";

	$message .= "<html>
	<head>
	<title>live24u/w3free Inquiry form</title>
	<style>
		table{width:100%; border:1px solid #cccccc;}
		table td, table th{border:1px solid #cccccc; padding:5px; font-size:12px; width:50%;}
		table th{text-align:left; color:#333333;}
		h3, h4, h5, h6 {margin:0; color:#333333;}
		.black {color:#000000;}
		body {font-family: 'Arial', sans-serif; font-size:10px; color:#333333; }
	</style>
	</head>
	<body style='width:700px;'>
 <br/>
 <h2>live24u/w3free Inquiry form</h2>
 <h2>Application Form</h2>
 <h2>Shaheed Park</h2>
	
	<table cellpadding='0' cellspacing='0' border='1'>
		<tbody>
			<tr>
				<td colspan='2'><h4>1. Live clients contact information</h4></td>
			</tr>
			<tr>
				<td class='black'>Name</td>
				<td>".$empname."</td>
			</tr>
			<tr>
				<td class='black'>Address</td>
				<td>".$resaddress."</td>
			</tr>
			<tr>
				<td class='black'>Phone Number</td>
				<td>".$phonumber."</td>
			</tr>
			<tr>
				<td class='black'>Email</td>
				<td>".$email."</td>
			</tr>
			<tr>
				<td class='black'>Website:(if applicable)</td>
				<td>".$myweb."</td>
			</tr>
			<tr>
				<td class='black'>img_gallery/Agent:(if any)</td>
				<td>".$gallery."</td>
			</tr>
			<tr>
				<td colspan='2' style='background-color:#cccccc'></td>
			</tr>
			<tr>
				<td colspan='2'><h3>Please provide the following Data</h3></td>
			</tr>
			<tr>
				<td class='black'>CV Links</td>
				<td>".$path.'Documents/'.$new_cvfilename."</td>
			</tr>
			<tr>
				<td class='black'>Media Links</td>
				<td>".$path.'dvd_data/'.$new_tempfilename."</td>
			</tr>
			<tr>
				<td colspan='2' style='background-color:#cccccc'></td>
			</tr>
			<tr>
				<td colspan='2'><h4>Please describe your creative practice with artistic development:</h4></td>
			</tr>
			<tr>
				<td colspan='2'>".$longdesc."</td>
			</tr>
			<tr>
				<td colspan='2' style='background-color:#cccccc'></td>
			</tr>
			<tr>
				<td colspan='2'><h4> I certify that, to the best of my knowledge the statements in this application are true.
</h4></td>
			</tr>
			<tr>
				<td class='black'>Full name</td>
				<td>".$firstname."</td>
			</tr>
			<tr>
				<td class='black'>Signature</td>
				<td>".$path.'sign/'.$new_signfilename."</td>
			</tr>
			<tr>
				<td class='black'>Date</td>
				<td>".$crdate."</td>
			</tr>
		</tbody>
	</table>
	<br/><br/>
	Best Regards<br/>
	live24u/w3free Inquiry form.<br/>
	</body>
	</html>  
	";


$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
//$mail->SMTPSecure = 'tls';
$mail->Host = 'ssl://smtp.Pakainfo.com';                // Specify main and backup server
$mail->Port = 465;  
$mail->SMTPDebug = 1;                                  // Set the SMTP port
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';                // SMTP username
$mail->Password = '[email protected]!$';                  // SMTP password
//$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted

$mail->From = '[email protected]';
$mail->FromName = 'live24u/w3free Inquiry form';// frome name
$mail->AddAddress($to,'live24u/w3free Inquiry form');
//$mail->AddAddress($to2,'live24u/w3free Inquiry form');
$path_cv_file = $path."dvd_data/Documents/".$data_link;
$path_media_file = $path."dvd_data/dvd_data/".$video_link;
$path_sign_file = $path."dvd_data/sign/".$sign_link;
$mail->addAttachment($path_cv_file, $data_link);
$mail->addAttachment($path_media_file, $video_link);
$mail->addAttachment($path_sign_file, $sign_link);
$mail->IsHTML(true);                                  // Set email format to HTML
$mail->Subject = $subject;
$mail->Body    = $message;
if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

$servername = "Pakainfo.com";
$username = "root";
$password = "";
$dbname = "my_contact";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO `contact_form` (`id`, `name`, `resaddress`, `ph_no`, `email`, `myweb`, `gallery`, `cv_link`, `media_link`, `long_desc`, `full_name`, `sign`, `date`, `status`) VALUES (NULL, '$empname', '$resaddress', '$phonumber', '$email', '$myweb', '$gallery', '$new_cvfilename', '$new_tempfilename', '$longdesc', '$firstname', '$new_signfilename', now(), '1')";

if (mysqli_query($conn, $sql)) {
    header("Location: index.php?message=success");
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>

Example

I hope you have Got What is how to store video file in mysql database using php And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1.   AngularJS Adding Form Fields Dynamically with PHP MySQLi
  2.   Get Content and Attributes using JavaScript jQuery
  3.   How to get difference between two dates in laravel?
  4.   Generate PDF in Laravel 5.8 example
  5.   Angularjs convert json string to array
  6.   vuejs Smooth Scroll to Top
  7.   delete Query In Codeigniter Example Tutorial
  8.   CodeIgniter Simple User Registration and Login System
  9.   Angular Pipes List Example Tutorial
  10.   Stripe API subscriptions with plan coupon and discounts using PHP