把 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_POST, true); 倒一下 curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);否则会有 413 Request Entity Too Large The requested resource .... does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.
当然也可以curl post过去
不是需要post整张图片过去么?
'f' => '@E:/xampp/htdocs/temp/1.jpg',
'a' => '1aaa'
);$ch = curl_init('http://localhost/temp/3.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, true);
$a = curl_exec($ch);
echo '<br>this is 2.php : <br>';
var_dump($a);
echo '<br>';
var_dump(curl_error($ch));
curl_close($ch);
3.php:echo 'this is 3.php : <br>';
var_dump($_REQUEST);
var_dump($_FILES);
echo '<br>';
执行后显示:
this is 3.php :
array(0) { } array(0) { } this is 2.php :
bool(true)
string(0) ""哪里出错了呢?
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, true);
倒一下
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);否则会有 413
Request Entity Too Large
The requested resource
....
does not allow request data with POST requests, or the amount of data provided in
the request exceeds the capacity limit.
<?php
$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);
?>
看手册curl那块,有这方面的例子
题外话,如果a并不需要保存图片实体的话,这种解决方案占用多一倍的磁盘写入时间和多一倍的带宽,还是直接传图给b好