Hi,

I am looking for a procedural PHP script that would allow me/my users to upload video content in a number of popular formats. I would also like all the information to be linked into a MySql database as well.

I already have a upload script for uploading documents but that only caters for word documents, so would it be possible just to change that to video extension and possibly add more extension types in an array and possibly increase the file size, the script is shown below:

include ('functions/config.inc.php');
include ('includes/header.php');
	
require (MySQL);
	
$uploadCV_errors = array();
	
   if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	
	if (preg_match ('/^[A-Z \'.-]{2,100}$/i', $_POST['name'])) {
	   $cvFirstName = mysqli_real_escape_string ($dbc, strip_tags($_POST['name']));
	} else {
	   $uploadCV_errors['name'] = 'Enter A Your First Name';
	}
		
	if (preg_match ('/^[A-Z \'.-]{2,100}$/i', $_POST['surname'])) {
	   $cvSurname = mysqli_real_escape_string ($dbc, strip_tags($_POST['surname']));
	} else {
	   $uploadCV_errors['surname'] = 'Enter A Your Surname';
	}
		
	if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $_POST['email'])) {
	   $cvEmail = mysqli_real_escape_string ($dbc, strip_tags($_POST['email']));
	} else {
	   $uploadCV_errors['email'] = 'Enter A Valid Email Address';
	}
		
	if (preg_match('/^[0-9 ]{1,15}$/i', $_POST['telephone'])) {
	   $cvTelephone = mysqli_real_escape_string ($dbc, strip_tags($_POST['telephone']));
	} else {
	   $uploadCV_errors['telephone'] = 'Enter Your Telephone Number';
	}
		
	if (!empty($_POST['comments'])) {
	   $allowed = '<div><p><span><br><a><img><h1><h2><h3><h4><ul><ol><li><blockquote><strong><em><del><ins>';
	   $cvComments = mysqli_real_escape_string($dbc, strip_tags($_POST['comments'], $allowed));
	} else {
	   $uploadCV_errors['comments'] = 'Please Enter Comments';
	}
		
	if (is_uploaded_file($_FILES['cv']['tmp_name']) && ($_FILES['cv']['error'] == UPLOAD_ERR_OK)) {
		
	   $file = $_FILES['cv'];
	   $size = ROUND($file['size']/1024);
			
	   if($size > 1024) {
		$uploadCV_errors['cv'] = 'The Uploaded File Was Too Large';
	   }
			
	   if( ($file['type'] != 'application/doc') && (substr($file['name'], -4) != '.doc') ) {
		$uploadCV_errors['cv'] = 'The uploaded file was not a Word Document';
	   }
			
	   if (!array_key_exists('doc', $uploadCV_errors)) {
		$tmp_name = sha1($file['name'] . uniqid('', true));
		$dest = CVs . $tmp_name . '_tmp';
						
		if (move_uploaded_file($file['tmp_name'], $dest)) {
			$_SESSION['cv']['tmp_name'] = $tmp_name;
			$_SESSION['cv']['size'] = $size;
			$_SESSION['cv']['file_name'] = $file['name'];
								
			//echo 'The file has been uploaded';
		} else {
			trigger_error('The file could not be moved.');
			unlink ($file['tmp_name']);
		}
	    } // END OF ARRAY KEY EXISTS
	} elseif (!isset($_SESSION['cv'])) {
	    switch ($_FILES['cv']['error']) {
	        case 1:
	        case 2:
		$uploadCV_errors['cv'] = 'The uploaded file was too large';
		break;
	        case 3:
		$uploadCV_errors['cv'] = 'The file was only partially uploaded.';
		break;
	        case 6:
	        case 7:
	        case 8:
		$uploadCV_errors['cv'] = 'The file could not be uploaded due to a system error.';
		break;
	        case 4:
		default:
		$uploadCV_errors['cv'] = 'No file was uploaded.';
		break;
	 }
     } // END of $_FILES IF-ELSE

     if(empty($uploadCV_errors)) {
			
       $fn = mysqli_real_escape_string($dbc, $_SESSION['cv']['file_name']);
       $tmp_name = mysqli_real_escape_string($dbc, $_SESSION['cv']['tmp_name']);
       $size = (int) $_SESSION['cv']['size'];
		
       $q = "INSERT INTO uploadedCVs(FirstName,Surname,Email,Telephone,Comments,tmp_name,file_name,size,date_created)VALUES('$cvFirstName','$cvSurname','$cvEmail','$cvTelephone','$cvComments','$tmp_name','$fn','$size',NOW() )";
       $r = mysqli_query($dbc, $q);
			
	if(mysqli_affected_rows($dbc) == 1) {
					
	      $original = CVs . $tmp_name . '_tmp';
	      $dest = CVs . $tmp_name;
	      rename($original, $dest);
						
		echo '<section class="content">
		      <aside class="leftPanel">
									<table class="featureBoxes" cellpadding="0" cellspacing="10">
										<tr>
											<td class="rounded lightBorder featureBox mediumColor mediumFill">
												<div class="feature feature1">
													<div class="featureTitle">1) Post A Job</div>
														Complete the form opposite with as much information as possible.
												</div>
											</td>
										</tr>
										<tr>
											<td class="rounded lightBorder featureBox mediumColor mediumFill">
												<div class="feature feature2">
													<div class="featureTitle">2) Call Back</div>
														We will then call you back to go through as much of the information
														as possible and sort out billing.
												</div>
											</td>
										</tr>
										<tr>
											<td class="rounded lightBorder featureBox mediumColor mediumFill">
												<div class="feature feature3">
													<div class="featureTitle">3) Invoice</div>
														We will then send out an invoice detailing your bill, we expect the
														bill to be paid within 7 days.
												</div>
							 				</td>
										</tr>
									</table>
								</aside>
													<article class="jobPanel">
														Congratulations, your CV has now been added to our database and if any of our jobs
														match your requirements then we will be in touch.
													</article>
											</section>';
											include('includes/footer.php');
											exit();
											
						$_POST = array();
						$_FILES = array();
						unset($file, $_SESSION['cv']);
					} else {
						trigger_error('The CV could not be added due to a system error. We apologise for any inconvenience.');
						unlink ($dest);
					}
			} else {
				unset($_SESSION['cv']);
			}
	}
?>

Any help would be much appreciated, thanks

Regards

This is the code that i have used in one of my application to upload video of any format.

include("media_handler.php");
if($Upload1)
    {
	//Flv Converter  
		$_mediahandler=new media_handler();
		$rootpath ="";
		$inputpath = $rootpath."Videos";
		$outputpath = $rootpath. "FLV";
		$thumbpath = $rootpath. "Thumbs";
		$outfile = "sample.png";
		$source = $HTTP_POST_FILES['video_upload']['tmp_name'];
		$name = $HTTP_POST_FILES['video_upload']['name'];
		$fileSize = $HTTP_POST_FILES['video_upload']['size'];
		$filetype = $HTTP_POST_FILES['video_upload']['type'];
	  
		$str_err="";
	    if($picname1=="")
	   	 {
			 $str_err.="<li>Video Name Missing";
		 }
	    
		
		
	  // This is for uploading video from local maching and converting into SWF using ffmpeg
	  		if($name != "")
	  			{
	  	    		$final_str = "";
					
					copy($source, $inputpath."/".$name);
					//echo $inputpath."/".$name."<br>";
					

					$outfile = $_mediahandler->convert_media($name,$rootpath, $inputpath, $outputpath, 320, 240, 32, 22050);
					$image_name = $_mediahandler->grab_image($outfile, $rootpath, $outputpath, $thumbpath, 1, 2, "png", 110, 90);
					if($image_name=="")
						$image_name="sample.png";
					$_mediahandler->set_buffering($outfile, $rootpath, $outputpath);
					$ffmpegcmd = "/usr/local/bin/ffmpeg -i Videos/$name -ar 22050 FLV/$name.flv";
					shell_exec($ffmpegcmd);
					
					$str='<div id="gddflvplayer"></div>
						<script type="text/javascript" src="../gddflvplayer/swfobject.js"></script>
						<script type="text/javascript">
							var so = new SWFObject("../gddflvplayer/gddflvplay-v32.swf", "gddflvplayer", "400", "360", "0", "#000000");
							so.addParam("quality", "best");
							so.addParam("allowScriptAccess", "always");
							so.addParam("allowFullScreen", "true");
							so.addVariable("vdo", escape("http://www.yoursite.com/FLV/'.$name.'.flv"));
							so.addVariable("desc", escape("'.$picname1.'"));
							so.addVariable("autoplay", "false");
							so.addVariable("sound", "100");
							so.write("gddflvplayer");
						</script>';

					//echo "INSERT INTO video_gallery(member_id,vgallery_name,vgallery,vgallery_big,public_option,dateadded,views,category,type) VALUES('".$_SESSION['SESS_MEMBER_ID']."','".$picname1."','".$image_name."','".$str."','".$option_val."','".date('Y-m-d H:i:s')."','0','".$str_cat."','flash')";
					$rs=mysql_query("INSERT INTO video_gallery(member_id,vgallery_name,vgallery,vgallery_big,public_option,dateadded,views,category,type,srcpath) VALUES('".$_SESSION['SESS_MEMBER_ID']."','".$picname1."','".$image_name."','".$str."','".$option_val."','".date('Y-m-d H:i:s')."','0','".$str_cat."','flash','FLV/".$name.".flv')"); 
		  			if($rs)
		  				{
		  	   				$str_err="Video Embedded Successfully";	   
		  				}
		  			else
		  				{
							$str_err="Failed to Embed Video";
		  				} 
 		  
		  			//echo "$str_err<br>";
		  			//print "<meta http-equiv='refresh' content='0;url=videogallery1.php'>";
	  			}
	}
/************** HTML *************************************/

<table width="100%"  border="0" align="center" cellpadding="2" cellspacing="0"  class="table-border">
                  <tr>
                      <td "height:22px;"class="header"><span style="padding-left:8px;"> Add Your Video </span></td>
                      </tr>
                      <tr>
                        <td ><table width="100%"  border="0" align="center" cellpadding="2" cellspacing="0">
                            <tr>
                              <td ><br />
                                <table width="90%"  border="0" align="center">
                                  <tr>
                                    <td height="180" align="center" valign="top"><table width="90%" border="0" align="center" cellpadding="2" cellspacing="0">
                                        <tr>
                                          <td width="189" height="25" align="left" class="headerfont">Video Name<span class="err">*</span></td>
                                          <td width="6" class="style3">&nbsp;</td>
                                          <td width="299" align="left" class="style4"><input name="picname1" type="text" class="textfield" id="picname1" /></td>
                                        </tr>
                                        <tr>
                                          <td align="right" class="style3">&nbsp;</td>
                                          <td>&nbsp;</td>
                                          <td height="25" align="left" class="style4">&nbsp;</td>
                                        </tr>
                                        <tr>
                                          <td align="left" class="headerfont">Public/Private</td>
                                          <td>&nbsp;</td>
                                          <td height="25" align="left" class="style4"><select name="option_val">
                                              <option value="public" selected="selected">Public</option>
                                              <option value="private">Private</option>
                                            </select></td>
                                        </tr>
                                        <tr>
                                          <td align="right" class="style3">&nbsp;</td>
                                          <td>&nbsp;</td>
                                          <td height="25" align="left" class="style4">&nbsp;</td>
                                        </tr>
                                        <tr>
                                          <td align="left" class="headerfont">Video Upload </td>
                                          <td>&nbsp;</td>
                                          <td height="25" align="left" class="style4"><input name="video_upload" type="file" class="textfield" id="video_upload" width="300" /></td>
                                        </tr>
                                        <tr>
                                          <td align="right" class="style3">&nbsp;</td>
                                          <td>&nbsp;</td>
                                          <td height="40" align="left" class="style4"><input name="Upload1" type="submit" class="colorbuttons" id="Upload1" value="Upload" /></td>
                                        </tr>
                                        <tr>
                                          <td align="right" class="style3">&nbsp;</td>
                                          <td>&nbsp;</td>
                                          <td height="25" align="left" class="err"><?=$str_err?></td>
                                        </tr>
                                      </table></td>
                                  </tr>
                                </table>
                                <br /></td>
                            </tr>
                          </table></td>
                      </tr>
                      <tr>
                        <td valign="top"><p> </p>
                          <p>&nbsp;</p></td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                    </table>

And this is media_handler.php file

<?php
class media_handler
{
	function convert_media($filename, $rootpath, $inputpath, $outputpath, $width, $height, $bitrate, $samplingrate)
	{
		$rPath = $rootpath."/ffmpeg";
		$size = $width."x".$height;
		$outfile = $filename.".swf";
		$ffmpegcmd1 = "/usr/local/bin/ffmpeg -i ".$inputpath."/".$filename. " -ar 22050 ".$outputpath."/".$outfile;
		//$ffmpegcmd1 = "ffmpeg -i ".$inputpath."\\".$filename. " -acodec mp3 -ar " .$samplingrate." -ab ".$bitrate."-f flv -s ".$size." ".$outputpath."\\".outfile;
		shell_exec($ffmpegcmd1);
		return $outfile;
		
	}

	function set_buffering($filename,$rootpath,$path)
	{
		return;
		// Not required for swf file
		$path = $rootpath."/FLV";
		//$ffmpegcmd1 = "/usr/bin/flvtool2 -U ".$path."/".$filename;
		//echo "$ffmpegcmd1 <br>";
		$ret = shell_exec($ffmpegcmd1);
	}
	
	function grab_image($filename, $rootpath, $inputpath,$outputpath, $no_of_thumbs, $frame_number, $image_format, $width, $height)
	{
		$outfile = "sample.png";
		$_rootpath = rootpath."/ffmpeg";
		$size = $width. "x".$height;
		$ffmpegcmd1 = "/usr/local/bin/ffmpeg -i ".$inputpath."/".$filename." -vframes ".$no_of_thumbs." -ss 00:00:03 -an -vcodec ". $image_format." -f rawvideo -s ".$size. " ". $outputpath."/".$outfile;
		shell_exec($ffmpegcmd1);
		return $outfile;
	}
}
?>

form.php

<html>
<body>

<form action="uploader.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

uploader.php

<?php
echo "Party Symbol<br/>";
if($_FILES["file"]["name"])
  {
  echo $_FILES["file"]["name"];
  echo $_FILES["file"]["tmp_name"];
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "./images/" . $_FILES["file"]["name"]);
           
      
 


   }

?>

This is the simplest script for uploading video but you must be sure that upload_max_filesize in your php.ini is given a higher value than the video size...
PS-If your problem is solved mark the thread as read....

how do i combine the files to produce the results? thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.