ftp_put(), move_uploaded_file() problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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,only 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: $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: $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: $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.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux