mindblown Posted February 15, 2013 Share Posted February 15, 2013 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> Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 15, 2013 Share Posted February 15, 2013 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; } } ?> Quote Link to comment Share on other sites More sharing options...
mindblown Posted February 15, 2013 Author Share Posted February 15, 2013 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> Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 15, 2013 Share Posted February 15, 2013 What is the file size uploading limit in your php.ini file? Quote Link to comment Share on other sites More sharing options...
mindblown Posted February 18, 2013 Author Share Posted February 18, 2013 Sry forgot about this post! I changed the limits and everything but I gave up on that for the moment. I moved on to other things in hopes that if i run into another problem that it will give me an idea on what is overall wrong. Don't know if that makes sense but thnx! Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 18, 2013 Share Posted February 18, 2013 Hm...that's weird Did you really increase the value of max_file_uploads in the php.ini directive? Quote Link to comment Share on other sites More sharing options...
Christian F. Posted February 18, 2013 Share Posted February 18, 2013 (edited) 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 February 18, 2013 by Christian F. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 18, 2013 Share Posted February 18, 2013 (edited) 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 February 18, 2013 by jazzman1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.