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