curlPost.php
<?php
$post = array(
'name' => 'wyjie',
'img' => '@D:/debug.exe'
);
//cURL发送post请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/demo/demo/curl/01.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$optput = curl_exec($ch);
curl_close($ch);
echo $optput;
?>
01.php
<?php
print_r($_POST);
print_r($_FILES);
?>
输出结果
Array ( [name] => wyjie [img] => @./debug.exe ) Array ( )
PHP 在5.4之后 不支持 @D:/debug.exe 的写法 。
所有为了兼容 ,可以这样写
if (class_exists('\CURLFile')) {
$param['file'] = new \CURLFile(realpath($file));
} else {
$param['file'] = '@' . realpath($file);
}