954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Copy file upload to ftp

I am trying to let users upload .flv files that will be played through flow player. While I am not getting an error, the file is not copying to the ftp folder. The upload script I have is

if ($_FILES["file1"]["type"] == "video/flv")
  {
$path1 = "uploads/".time().'.'.$HTTP_POST_FILES['file1']['name'];
$path1 = str_replace (" ", "", $path1);
$path1 = str_replace("#", "No.", $path1); 
$path1 = str_replace("$", "Dollar", $path1); 
$path1 = str_replace("%", "Percent", $path1); 
$path1 = str_replace("^", "", $path1); 
$path1 = str_replace("&", "and", $path1); 
$path1 = str_replace("*", "", $path1); 
$path1 = str_replace("?", "", $path1); 

if ($_FILES["file1"]["error"] > 0)
  {
  header("location:video.php");
  die();
  }
else
  {
  copy($_FILES["file1"]["tmp_name"],$path1);
  }
  }
megachip04
Light Poster
34 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

Try to add video/x-flv to the conditional statement.

cereal
Master Poster
709 posts since Aug 2007
Reputation Points: 214
Solved Threads: 120
 
Try to add video/x-flv to the conditional statement.

this seems to have done the trick, could you explain what the x- means?

megachip04
Light Poster
34 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

Great! :) On linux there is the command file that gives you the correct mime-type for each file:

file --mime video.flv


the result isvideo.flv: video/x-flv; charset=binary

cereal
Master Poster
709 posts since Aug 2007
Reputation Points: 214
Solved Threads: 120
 

$HTTP_POST_FILES is T.Rex's extinct uncle (deprecated 4.1.0). Try $_FILES instead.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

One more suggestion, instead of this many str_replaces, use arrays to replace the relevant chars.

lampfreaks
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 1
 
One more suggestion, instead of this many str_replaces, use arrays to replace the relevant chars.

how might that be done?

megachip04
Light Poster
34 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

This way:

$a = array(' ','#','$','%','^','&','*','?');
$b = array('','No.','Dollar','Percent','','and','','');
$path1 = str_replace($a,$b,$path1);
cereal
Master Poster
709 posts since Aug 2007
Reputation Points: 214
Solved Threads: 120
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: