Page 1 of 1

Posting a File from one Host Server to Another...how??

Posted: Wed Oct 24, 2012 10:02 am
by simonmlewis
I have a client who has multiple web sites of one domain. Such as a .com, and a .co.uk.
They want to be able to Go to a product in the .com, and say "Sell on ***.co.uk".

That they passes thru the description, and other field date. EASY.
But, they also want to be able to pass thru the image, or images to that site server.

Whereas right now you would create the product, 'Browse', choose file from your PC folder, and Upload, and it runs thru the PHP Script. I need it to pass the image, or images from one hosted server, to an entirely separate hosted (separate company hosting it too) server.

Can this be done?
Is there a term for it online I can research?
The client said "I don't know if this is possible". But I like to try and achieve the impossible, so would be rather impressive!!!!

Code: Select all

<?php
$url = 'http://www.example.com/file.zip';
if (@copy($url, basename($url)))
{
    echo 'File saved.';
}
?>
Just found this - would it work? Tho it doesn't state the two URLs.

Many thanks in advance.

Simon

Re: Posting a File from one Host Server to Another...how??

Posted: Wed Oct 24, 2012 11:38 am
by Christopher
There are lots of different ways to do this. Probably using PHP's ftp or cURL libraries would be the simplest. Are these sites on different servers?

Re: Posting a File from one Host Server to Another...how??

Posted: Wed Oct 24, 2012 11:42 am
by simonmlewis
Yes they are. PHP's ftp seems to be a good method. Been testing this afternoon. So far so... partly good.

Re: Posting a File from one Host Server to Another...how??

Posted: Thu Nov 08, 2012 6:19 am
by simonmlewis
This isn't working. It's saying:
Warning: ftp_put(/images/productphotos/$row->photoprimary) [function.ftp-put]: failed to open stream: No such file or directory in /home/site/public_html/includes/a_crossproductcopy.inc on line 83
There was a problem while uploading ../images/productphotos/$row->photoprimary

Code: Select all

$file = '/images/productphotos/$row->photoprimary';
      $remote_file = '/images/productphotoss/';

      // set up basic connection
      $conn_id = ftp_connect($ftp_server);
      // login with username and password
      $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
      // upload a file
      if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) 
        {
        echo "Successfully uploaded to $site: $file\n";
        }
        else 
        {
        echo "There was a problem while uploading $file\n";
        }
      ftp_close($conn_id);
The URL of the photoprimary is correct as I've tested it with an <img> tag.

Re: Posting a File from one Host Server to Another...how??

Posted: Thu Nov 08, 2012 8:09 am
by Tiancris

Code: Select all

$file = '/images/productphotos/$row->photoprimary'
Use double instead of single quotes! :)