Shameem
Shameem

Reputation: 317

How to upload images from one server to another using php

I have a php file to upload an image. while uploading image i need to upload the same image to another server also. I tried with php ftp. but it showing an error unable to connect ftp. how to solve this error? or any other method to do this.

my ftp connection code is

$ftp_server="";
$ftp_user_name="";
$ftp_user_pass="";

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if ((!$conn_id) || (!$login_result)) {
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user_name";
    die;
} else {
    echo "<br>Connected to $ftp_server, for user $user<br>";
}

Iam using shared hosting server

Upvotes: 3

Views: 3839

Answers (2)

Ivan Dubynets
Ivan Dubynets

Reputation: 431

As alternative of ftp, you can use nfs or some other share.

The idea is that all your servers have mounted directly with the same structure. You will work with this directory as with normal file system and nfs will do synchronization for you.

Upvotes: 0

Tech
Tech

Reputation: 56

you can do with this by calling a page using curl from first server. in that page you can write function to upload remote images.

you can check this question for reference PHP - Upload an image file to other domain with CURL

Upvotes: 1

Related Questions