php – 用cURL转移图像

我有2台服务器.我想用cURL将文件从一台服务器传输到另一台服务器.有人能告诉我一个很好的例子吗?我应该给cURL什么选择…..

谢谢.

解决方法:

sender.PHP

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// true to return the transfer as a string of the return value
// of 'curl_exec' instead of outputting it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, 'http://localhost/test/curl/receiver.PHP');
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
  'euro' => '@eurodance.pls',
  'flush' => '@flush_next.png',
  'first_name' => 'Vadim'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
print_r($response);

receiver.PHP

if(isset($_FILES)){
  $temp_file_name = $_FILES['euro']['tmp_name'];
  $original_file_name = $_FILES['euro']['name'];

  // Find file extention
  $ext = explode ('.', $original_file_name);
  $ext = $ext [count ($ext) - 1];

  // Remove the extention from the original file name
  $file_name = str_replace ($ext, '', $original_file_name);

  $new_name = '_'.$file_name . $ext;
//echo $file_name ." ". $ext;

  if (move_uploaded_file ($temp_file_name, $new_name)) {
      echo "success";
   } else {
      echo "error";
    }

}
if(isset($_FILES)){
  $temp_file_name = $_FILES['flush']['tmp_name'];
  $original_file_name = $_FILES['flush']['name'];

  // Find file extention
  $ext = explode ('.', $original_file_name);
  $ext = $ext [count ($ext) - 1];

  // Remove the extention from the original file name
  $file_name = str_replace ($ext, '', $original_file_name);

  $new_name = '_'.$file_name . $ext;
//echo $file_name ." ". $ext;

  if (move_uploaded_file ($temp_file_name, $new_name)) {
      echo "success";
   } else {
      echo "error";
    }

}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...