0

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

5
Contributors
7
Replies
22
Views
7 Years
Discussion Span
Last Post by diafol
0

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...

0

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,

0

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..

0

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!

0

Thanks, so much...

Works great...

Really appreciate it!

happy to know that :)

Edited by network18: n/a

0
<?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);
}
?> 
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.