Jump to content

Upload Video


mindblown

Recommended Posts

i wrote an a simple upload form and then another php file to process the form.

the form works on all the files i have tried to upload except for videos. Can anyone tell me what's going on?

I'm getting undefined index errors when trying to upload videos but not pictures.

Here are my scripts

 

(index.php)

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<form action="get.php" method="post" enctype="multipart/form-data">

<input type="text" name="title" /><br/>

<input type="file" name="pictu" /><br/>

<input type="submit" name="Sumber" value="ClickClack" />

</form>

</html>

 

(get.php)

 

 

<?php

 

 

 

$fist=$_FILES["pictu"]["tmp_name"];

$deuce= "upload/" . $_FILES["pictu"]["name"];

$con = mysql_connect("localhost","root","");

move_uploaded_file($fist,$deuce);

$select= mysql_select_db("project", $con);

$sql="INSERT INTO media (Name, pic) VALUES('".$_POST['title']."', '".$_FILES['pictu']['name']."')";

$poster=$_POST['Sumber'];

echo "Stored in: " . "$deuce";

 

if(isset($poster))

{$con;

$slect;}

 

if (!$con)

 

{echo('Could not connect: ' . mysql_error());}

 

 

if (!mysql_query($sql,$con))

 

{echo('Error: ' . mysql_error());}

 

mysql_close($con);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<iframe src="<?php echo "$deuce" ?>">

</iframe>

</body>

</html>

Link to comment
Share on other sites

Stop using mysql_*, start to learn MySQLi or PDO.

 

Ok, moving on....I've rewritten a little your get.php file.

 

<?php
error_reporting(-1);
$conn = mysql_connect('localhost', 'jazzman', 'password', 3306) or die(mysql_error());
$db_name = mysql_select_db('test', $conn) or die(mysql_error());
$img = $_FILES["pictu"]["name"];
$imgTitle = $_POST['title'];
if (!empty($img)) {
$imgName = $_FILES["pictu"]["name"];
$deuce = "upload/" . $imgName;
if (move_uploaded_file($_FILES['pictu']['tmp_name'], $deuce)) {
 $sql = sprintf("INSERT INTO media (`Name`, `pic`) VALUES('%s','%s')", mysql_real_escape_string($imgTitle), mysql_real_escape_string($imgName));
 $result = mysql_query($sql) or die(mysql_error());
 printf("Inserted records: %d\n", mysql_affected_rows());
 mysql_close($conn);

} else {
 echo 'Moving file upload failed!';
 exit;
}
}
?>

Link to comment
Share on other sites

Thanks! but this one only works with pictures and other files but not video its giving me an ( ! ) Notice: Undefined index: pictu in C:\wamp\www\closer\get1.php on line 5 Call Stack # Time Memory Function Location 1 0.0013 145176 {main}( ) ..\get1.php:0 ( ! ) Notice: Undefined index: title in C:\wamp\www\closer\get1.php on line 6 Call Stack # Time Memory Function Location 1 0.0013 145176 {main}( ) ..\get1.php:0

error. Any ideas?

 

 

<?php

error_reporting(-1);

$conn = mysql_connect('localhost', 'root', '') or die(mysql_error());

$db_name = mysql_select_db('project', $conn) or die(mysql_error());

$img = $_FILES["pictu"]["name"];

$imgTitle = $_POST['title'];

if (!empty($img)) {

$imgName = $_FILES["pictu"]["name"];

$deuce = "upload/" . $imgName;

if (move_uploaded_file($_FILES['pictu']['tmp_name'], $deuce)) {

$sql = sprintf("INSERT INTO media (`Name`, `pic`) VALUES('%s','%s')", mysql_real_escape_string($imgTitle), mysql_real_escape_string($imgName));

$result = mysql_query($sql) or die(mysql_error());

printf("Inserted records: %d\n", mysql_affected_rows());

mysql_close($conn);

 

} else {

echo 'Moving file upload failed!';

exit;

}

}

?>

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<form action="get1.php" method="post" enctype="multipart/form-data">

<input type="text" name="title" /><br/>

<input type="file" name="pictu" /><br/>

<input type="submit" name="Sumber" value="ClickClack" />

</form>

</html>

Link to comment
Share on other sites

The problem is most certainly one of timing out, which means that your array isn't filled out. Seeing as you do not check for errors before attempting to use any of the data, you get warnings about undefined indices at that point.

 

Morale of this story: Always check for errors at every turn, especially when it comes to user-generated content. ;)

Edited by Christian F.
Link to comment
Share on other sites

That's a part of my php.ini directive on the local machine, everything works just fine.

 


file_uploads = On

upload_max_filesize = 2048M

max_file_uploads = 2M

post_max_size = 2048M

 


<?php

error_reporting(-1);

echo 'file count=', count($_FILES),"\n";
var_dump($_FILES);
echo "\n";
?>

<form enctype="multipart/form-data" action="debug.php" method="POST">
 Choose a file to upload: <input name="uploadedFile" type="file" /><br />
 <input type="submit" value="Upload File" />
</form>

 

Results:

 

 

file count=1

array

'uploadedfile' =>

array

'name' => string 'test.wmv' (length="8")

'type' => string 'video/x-ms-wmv' (length=14)

'tmp_name' => string '/tmp/phpYNlCMK' (length=14)

'error' => int 0

'size' => int 36086115

 

 

The test has been made it with 36086115 bytes (34.4MB) video file.

Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.