PHP form upload for videos (stopped working)
Hi I created some codes to upload my videos on the website, but for some reason it stopped working.
Can Someone please help me debug the issues thanks!
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$database = "name_of_database";
$db = mysql_connect($hostname, $username, $password);
mysql_select_db($database, $db);
$path = "videos/";
//check to see if directory already exist
if(!file_exists($path))
{
//creating directory
mkdir($path, 0777);
$path = $path;
}
else
{
$path = $path;
}
$filename = $_FILES['videofile']['name']; //Find the Extension so I can change the file name
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
$ext = findexts($_FILES['videofile']['name']);
$rand = rand ();
$ran = 'vid_'.$rand;
$ran2 = $ran.'.';
$target = 'videos/';//File Location
$target = $target.$ran2.$ext;
$location = $path.$ran2.$ext;
if(move_uploaded_file($_FILES['videofile']['tmp_name'], $target)) {
mysql_query("INSERT INTO video (video_link) VALUES ('$location')");
header("Location:video.php?w=ok&f=".$location);
} else{
header("Location:video.php?error=1");
echo "Error when uploading the video.";
}
?>
For some reason it keeps going to the Else statement verses the "If".
Thank you in advance
programmer12
Junior Poster in Training
79 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
What do you mean it stopped working? What did you change? WHich if/else - you have two lots of if/elses. I' assuming the last one.
use pathinfo() in order to extract extension - it's safer.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Yes i am referring to the Last IF Statement. It by passes the IF and goes straight to the ELSE.
I also noticed that when i do a
print_r($_FILES)
;. It reads back to me
Type: [blank]
Size:0
Error: 1
How do I make sure that the file is being moved.
It was working before, but not sure why it stopped working.
Now its telling me that the
$exts = split("[/\\.]", $filename) ;
is deprecated???
programmer12
Junior Poster in Training
79 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
ok i just noticed as well that the file is not moving to the Temp folder anymore so When it attempts to move the file to uploaded area it comes up blank? How can i fix that?
programmer12
Junior Poster in Training
79 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
$username = "root";
$password = "";
$hostname = "localhost";
$database = "name_of_database";
$db = mysql_connect($hostname, $username, $password);
mysql_select_db($database, $db);
if(!file_exists($path)) {
mkdir($path, 0777);
$path = $path;
}
$filename = $_FILES['videofile']['name'];
$f = pathinfo($filename);
$rand = rand ();
$ran = 'vid_'.$rand . $f['extension'];
$path = 'videos/';
$target = $path.$ran;
if(move_uploaded_file($_FILES['videofile']['tmp_name'], $target)) {
mysql_query("INSERT INTO video (video_link) VALUES ('$target')");
if(mysql_affected_rows()>0){
header("Location:video.php?w=ok&f=".$location);
exit;
}else{
echo "Could not insert $target into DB";
}
} else{
header("Location:video.php?error=1");
exit;
//echo "Error when uploading the video."; - no point in this once header run
}
SHoiw the upload form if this doesn't work.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
I just tried out the codes, the folder is created but nothing is uploaded. Any other suggestions?
(Do you think the move_uploaded_file is not carrying out the codes? because it skips over that piece of codes and goes straight to error)
programmer12
Junior Poster in Training
79 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
Sorry mate - at my age it takes time to reacquaint yourself with a problem. I wrote that bit of code too long ago to remember what I was trying to do. Anybody else?
Sorry if this post does nothing other than bump it. :)
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080