How to transfer file from one server to another server in php?
Asked
Active
Viewed 1,672 times
-1
-
2http://php.net/manual/en/book.curl.php – Kazz Jun 03 '17 at 04:37
-
Does this need to be a one time transfer or ongoing – Jeremy Hamm Jun 03 '17 at 04:38
-
3@Kazz Can I transfer file using curl? I think I transfer files using curl – Hardik Chapla Jun 03 '17 at 04:38
-
I imagine you could do it with FTP, thought i have not got through it thuroughly: http://php.net/manual/en/book.ftp.php – Rasclatt Jun 03 '17 at 04:48
2 Answers
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
-
Have you try this code anywhere? and thank for your suggestion. :) – Hardik Chapla Jun 03 '17 at 04:44
-
1You can check first accepted answer [HERE](https://stackoverflow.com/questions/9843933/copy-file-from-remote-server-or-url) – jirarium Jun 03 '17 at 04:47
-
yes I have check but using curl is easy for transfer file without web forms, so i use curl – Hardik Chapla Jun 03 '17 at 04:55
-
1
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’);
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