PHP中JSON的cURL-POST不起作用


cURL to JSON in PHP - POST not working

我有下面的cURL命令,可以将图像添加到我的服务器中,效果很好:

curl -i -X POST -u user:pw -F 'post[image]'=@image.jpg http://domain.com/post.json

现在我想用PHP实现这一点。除了"post[image]"=@image.jpg部分,我似乎什么都做得很好。

我需要将什么传递到我的curl_setopt($ch, CURLOPT_POSTFIELDS)字段才能使其工作?有人能帮我吗?

$url = 'host/script.php';
$post = array('image' => '@image.jpg');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);
curl_close($ch);