Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用curl和php将文件上传到另一个文件?_Php_Curl - Fatal编程技术网

如何使用curl和php将文件上传到另一个文件?

如何使用curl和php将文件上传到另一个文件?,php,curl,Php,Curl,并获取响应?sender.php $ch = curl_init(); $data = array('name' => 'img', 'file' => $_FILES["img"]["tmp_name"].".png"); curl_setopt($ch, CURLOPT_URL, 'http://www.postto.me/upload.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTF

并获取响应?

sender.php

$ch = curl_init();
$data = array('name' => 'img', 'file' => $_FILES["img"]["tmp_name"].".png");
curl_setopt($ch, CURLOPT_URL, 'http://www.postto.me/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
receiver.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);
如您所见,它支持多个文件上载。

sender.php

$ch = curl_init();
$data = array('name' => 'img', 'file' => $_FILES["img"]["tmp_name"].".png");
curl_setopt($ch, CURLOPT_URL, 'http://www.postto.me/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
receiver.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);

正如您所看到的,它支持多个文件上传。

您能再补充一点吗?你有什么问题?自欺欺人?是的,任何人都可以在你的服务器上执行此请求。你能再多说一点吗?你有什么问题?自欺欺人?是的,任何人都可以在您的服务器上执行此请求。