如何在PHP cURL中使用-F?

如何在PHP cURL中使用-F?,php,curl,Php,Curl,我有以下curl控制台命令 curl -i -X POST -u USERNAME:PASSWORD https://foo.com/api/metadata/ -F key="url" -F value="http://foo.com" curl -i -X POST -u USERNAME:PASSWORD https://foo.com/api/queries/ -F image=@/tmp/image.jpg 如何在PHP cURL中传递-F参数值在post字段中添加文件,然后像下面的

我有以下curl控制台命令

curl -i -X POST -u USERNAME:PASSWORD https://foo.com/api/metadata/ -F key="url" -F value="http://foo.com"
curl -i -X POST -u USERNAME:PASSWORD https://foo.com/api/queries/ -F image=@/tmp/image.jpg

如何在PHP cURL中传递
-F
参数值在post字段中添加文件,然后像下面的代码一样使用cURL:

$post = array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
注意:使用
realpath()
获取文件路径


可能需要在PHP cURL中查找
CURLOPT\u POSTFIELDS
选项