I've done this a hundred times using move_uploaded_file but never realized till now that it only works adding files to a directory on the same server. $target_path = 'files/uploadedimage/'; $target_path = $target_path .basename($_FILES['uploadedfile']['name']); Now I'm stuck with the task of an internal server for uploading files but the directory needs to end up on the external server. Is this even possible? $target_path = 'http://mywebsite/files/uploadedimage/'; $target_path = $target_path .basename($_FILES['uploadedfile']['name']); Any help would be appreciated. I've been scouring Google for weeks trying to find the answer but having no luck. I'm running php on an IIS server if that matters, not my choice
Connect to destination server via ftp_connect and use ftp_put (http://php.net/manual/en/function.ftp-put.php) $destination_directory="public_html/my_folder/"; $source_directory="/home/username/my_source_folder/file1.jpg"; $ftp_server = "site.com"; $ftp_username = "username"; $ftp_password = "password"; $ftp_connection = ftp_connect($ftp_server); $connection_result = ftp_login($ftp_connection, $ftp_username, $ftp_password); $upload = ftp_put($ftp_connection, $destination_directory, $source_directory, FTP_BINARY); PHP: I hope this helps!
You will have to write it yourself. Still that's not so tricky, accept the upload, move it to a temporary location ( where you have permissions ), don't leave it in temp less another system service wipes the directory and you loose the data during the operation. The next part depends on what you can run on the destination, if you can't run anything at the destination then I'd go with ftp to move the file to the correct server, if you can script at the destination then you can send the file with cURL, or construct the request yourself, the code at the destination server should just accept the temporary file upload and move it to the final destination .... For the sake of script timeouts, you might want to avoid executing php, and instead use FTP/SCP commands to move the file, appending & to the exec'd command will force the process that does the actual donkey work into the background and your script should not timeout. Simples ...
Thanks a lot. This does help big time but I will have to convince the grumpy old IT guy who is on vacation ATM to create an FTP user. This at least points me in the write direction. Again, Thanks!
If the final destination is unix and you have a shell account you can use the login you use to get a shell ... If you have secure shells setup, and you should have, being that you have a grumpy IT guy, you shouldn't need to provide a password.... Or wait for grumpy