发送的代码(完全是官方的示例)
<?php
/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/
$ch = curl_init();
$data = array('name' => 'Foo', 'file' => '@/home/vagrant/test.png');
curl_setopt($ch, CURLOPT_URL, 'http://localhost/test/curl/load_file.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
?>
接收代码(也是官方的)
<?php
print_r($_POST);
print_r($_FILES);
运行结果
php -f demo.php
Array
(
[name] => Foo
[file] => @/home/vagrant/test.png
)
Array
(
)
本来准备贴php.ini配置的,但是没找到上传地方。请各位先看看,需要哪些配置我尽快贴出来。
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);我也加过,内容打印出来视乎帮助不大。
PHPz2017-04-10 15:56:48
$ch = curl_init();
$data = array('name' => 'Foo', 'file' => '@/home/vagrant/test.png');
curl_setopt($ch, CURLOPT_URL, 'http://localhost/test/curl/load_file.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); // 5.6 给改成 true了, 弄回去
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
?>