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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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?
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post by simonmlewis »

Yes they are. PHP's ftp seems to be a good method. Been testing this afternoon. So far so... partly good.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Tiancris
Forum Commoner
Posts: 39
Joined: Sun Jan 08, 2012 9:54 pm
Location: Mar del Plata, Argentina

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

Post by Tiancris »

Code: Select all

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