Hi Guys

I am creating a site and i want users to be able to upload videos to a folder on a server, using SQL to store the path of the video and the name.

I have created this Code. And it does upload all the details, but does not upload the video itself...

<?
session_start();
require("connection.php");

$title = mysql_real_escape_string($_POST['title']);
$date = mysql_real_escape_string($_POST['date']);
$author = mysql_real_escape_string($_POST['author']);
$type = mysql_real_escape_string($_POST['type']);
$description = mysql_real_escape_string($_POST['description']);

$vidName = $_FILES['vid']['name'];
$vidTmp = $_FILES['vid']['tmp_name'];
$vidSize = $_FILES['vid']['size'];

$maxFileSize = 2000000;
$filePath = "uploads/videos/".$vidName;

	move_uploaded_file($imgTmp, $filePath);
	$query = sprintf("INSERT INTO videos(title, date, author, description, type, vid) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')", $title, $date, $author, $description, $type, $filePath);
	if(!mysql_query($query, $connect)) {
	die(mysql_error());
	} else {
	echo("Choose a video!");
	}

?>

Can anybody tell me where im going wrong or give me some advice?

Thanks,

Evan

Hi Guys

I am creating a site and i want users to be able to upload videos to a folder on a server, using SQL to store the path of the video and the name.

I have created this Code. And it does upload all the details, but does not upload the video itself...

<?
session_start();
require("connection.php");

$title = mysql_real_escape_string($_POST['title']);
$date = mysql_real_escape_string($_POST['date']);
$author = mysql_real_escape_string($_POST['author']);
$type = mysql_real_escape_string($_POST['type']);
$description = mysql_real_escape_string($_POST['description']);

$vidName = $_FILES['vid']['name'];
$vidTmp = $_FILES['vid']['tmp_name'];
$vidSize = $_FILES['vid']['size'];

$maxFileSize = 2000000;
$filePath = "uploads/videos/".$vidName;

	move_uploaded_file($imgTmp, $filePath);
	$query = sprintf("INSERT INTO videos(title, date, author, description, type, vid) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')", $title, $date, $author, $description, $type, $filePath);
	if(!mysql_query($query, $connect)) {
	die(mysql_error());
	} else {
	echo("Choose a video!");
	}

?>

Can anybody tell me where im going wrong or give me some advice?

Thanks,

Evan

You may need to change

move_uploaded_file($imgTmp, $filePath);

to

move_uploaded_file($vidTmp, $filePath);

See if that does anything.

Cheers...

You may need to change

move_uploaded_file($imgTmp, $filePath);

to

move_uploaded_file($vidTmp, $filePath);

See if that does anything.

Cheers...

Thanks,

Tried that and still doesn't work... it also adds blank fields within my table on SQL??

Any ideas?

Thanks,

I am sure the entire code to upload is not inside the post check of submit button like -

session_start();
require("connection.php");

if(isset($_POST['submit_btn_name']) && $_POST['submit_btn_name']!='')
{
//put your remaining code (what you posted above) here
}

and that's the reason you getting the blank rows in the database..

I am sure the entire code to upload is not inside the post check of submit button like -

session_start();
require("connection.php");

if(isset($_POST['submit_btn_name']) && $_POST['submit_btn_name']!='')
{
//put your remaining code (what you posted above) here
}

and that's the reason you getting the blank rows in the database..

Thanks, so much...

Works great...

Really appreciate it!

Thanks, so much...

Works great...

Really appreciate it!

happy to know that :)

<?php
//Hi its me NADEEM....this script works but only for less then 2Mb file...so what i need to do with this...can any one help me...
error_reporting(E_ALL ^ E_NOTICE); // Show all major errors.

// Check to see if the button has been pressed
if (!empty($_REQUEST['sendForm']))
{
// Assign the name to a variable
$name = $_FILES['uploaded_file']['name'];
// Assign the tmp_name to a variable
$tmp_name = $_FILES['uploaded_file']['tmp_name'];
// Assign the error to a variable
$error = $_FILES['uploaded_file']['error'];
// Assign the size to a variable
$size = $_FILES['uploaded_file']['size'];
// No trailing slash, folder where you want it uploaded too
$uploadFilesTo = 'video';
// Create safe filename

// Disallowed file extensions
$naughtyFileExtension = array("php", "php3", "asp", "inc", "txt", "wma", "mov", "js", "exe", "jsp", "map", "obj", "gif", "html", "mp3", "mpu", "wav", "cur", "ani");
// Returns an array that includes the extension
$fileInfo = pathinfo($name);
// Check extension
if (!in_array($fileInfo['extension'], $naughtyFileExtension))
{
// Get filename
$name = getNonExistingFilename($uploadFilesTo, $name);
// Upload the file
if (move_uploaded_file($tmp_name, $uploadFilesTo.'/'.$name))
{
// Show success message
echo 'File uploaded to /'.$uploadFilesTo.'/'.$name;
}
else
{
// Show failure message
echo '<center><p>File failed to upload to /'.$name.'</p></center>';
}
}
else
{
// Bad File type
echo '<center><p>The file uses an extension we don\'t allow.</p></center>';
}
}

// Functions do not need to be inline with the rest of the code
function getNonExistingFilename($uploadFilesTo, $name)
{
if (!file_exists($uploadFilesTo . '/' . $name))
return $name;

return getNonExistingFilename($uploadFilesTo, rand(100, 200) . '_' . $name);
}
?> 
Member Avatar for diafol

You need to change your settings to allow files > 2Mb - see your php.ini file.

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.