-1

How to transfer file from one server to another server in php?

Hardik Chapla
  • 435
  • 6
  • 26

2 Answers2

2

You can try :

$remote_file_url = 'http://some--url/file.zip';

/* New file name and path  */
$local_file = 'file.zip';

/* Copy the file from source url to server */
$copy = copy( $remote_file_url, $local_file );

/* Add notice for success/failure */
if( !$copy ) {
    echo "failed to copy $file...\n";
}
else{
    echo " success to copy $file...\n";
}
jirarium
  • 182
  • 2
  • 7
1

using CURL You can transfer files from one server to another server.

Here is example :

Uploading file

<?php

/* http://localhost/upload.php: print_r($_POST); print_r($_FILES); */

$ch = curl_init();

$data = array(‘name’ => ‘Foo’, ‘file’ => ‘@/home/user/test.png’);

curl_setopt($ch, CURLOPT_URL, ‘http://localhost/upload.php&#8217;);

curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch); ?>
Hardik Chapla
  • 435
  • 6
  • 26
Prit
  • 26
  • 3
  • Sir the above code is to transfer the file.how can i fetch and insert the file to folder on the other side ? – Nisha Jun 29 '18 at 06:37