简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM