0

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

3
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by veedeoo
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.

0

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

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?

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.

0

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)

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

Edited by diafol: n/a

0

Hi,

Before anything else, can you please check what is the value of your upload_max_filesize and post_max_size. These are in the php.ini file or on your loaded server configuration file.

I also suspect that your server's php version has been upgraded..

Just copy, save, name anyNameYouWant.php, upload to your server, and then direct your browser to this file. Look up for the values of those items I have mentioned above.

<?php 
phpinfo(); 
?>

Another question I have, what do you do with the video extensions not supported by flash player? Is it encoded? If yes? by What?

about the deprecated function, Ardav already corrected it on his proposed solution

$exts = split("[/\\.]", $filename) ;

Was replaced by this

$f = pathinfo($filename);

Or you can use one of my favorite

## derived from your function above
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = strtolower(substr($filename, strrpos($filename, '.') + 1));
return $exts;
} 

## testing the function above.. it should return flv
$some_file = "somevideo.flv";
echo (findexts($some_file));

Edited by veedeoo: n/a

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.