如何在php中将文件从一台服务器传输到另一台服务器?
答案 0 :(得分:2)
您可以尝试:
$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";
}
答案 1 :(得分:1)
使用CURL您可以将文件从一台服务器传输到另一台服务器。
以下是示例:
上传文件
<?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); ?>