Page 1 of 1

[RESOLVED]move_uploaded_file() conflicting with ftp_put()

Posted: Wed Aug 03, 2005 9:16 am
by tripwater
Hello, I have a site that allows developers to upload current modules to the webserver. It has been requested that when this is done, I also ftp a backup copy to a remote server. Something is wrong here. The file upload code works. The back ftp code works, if I comment out the move_uploaded_file() function. I can not get them both to work. After the move_uploaded_file() function moves the file to the webserver, the ftp_put() fails, but if I comment out the move_uploaded_file(), the ftp_put() works. Can anyone help me with this? I have posted this on other forums and working on this for a couple of weeks now.


1. I am uploading the module to the webserver.
2. Then in the next step want to ftp same module to backup server.

So Step 1

Code: Select all

$path 	= "../modules";

if (!is_dir($path))
   mkdir($path,0700);		
	
	
if (!move_uploaded_file($_FILES['srcfile']['tmp_name'], $path."/".strtolower(trim($_FILES['srcfile']['name']))))
Which works. THis uploads the module to the webserver to the set location


then Step 2

Code: Select all

$ftp = ftp_connect('server goes here');

			
// login with username and password
if (ftp_login($ftp, 'username', 'password'))
   {
   ftp_pasv ( $ftp, true );
				
				
				
   if (ftp_put($ftp, "public_html/temp/" . $_FILES['srcfile']['name'], $_FILES['srcfile']['tmp_name'], FTP_BINARY)) 
      {
      $message = "File uploaded";
      }
      else 
      {
      die("Could not upload file");
      }
   }
else 
   {
   die("Could not login to FTP account");
   }
				
if (!empty($message)) 
   {
   echo $message;
   }
			
// close the FTP stream
ftp_close($ftp);

The only way this second FTP code works is if I comment out the first upload code,

Code: Select all

$path 	= "../modules";

if (!is_dir($path))
   mkdir($path,0700);		
	
	
//if (!move_uploaded_file($_FILES['srcfile']['tmp_name'], $path."/".strtolower(trim($_FILES['srcfile']['name']))))
Can anyone tell me if the problem is a ftp stream being left open and that is why I can not get the second portion of my code to work? Is there a way to get both of these to work together? I need not only to be able to upload to the webserver but ftp a backup copy to the remote server as well.

Thank you for any help.

Posted: Wed Aug 03, 2005 2:25 pm
by tripwater
This problem was solved for me on another forum
You used move_uploaded_file() to move the file to $path.

Quote:
Originally Posted by php manual.move_uploaded_file
If the file is valid, it will be moved to the filename given by destination


The file is no longer in temp.

try ftp_put($ftp, $path)