2013-08-31 65 views
0

我有以下cURL命令,将图像添加到我的服务器,它工作得很好:卷曲成JSON在PHP - POST不工作

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

现在我想在PHP这项工作。我似乎得到了一切正常,除了'post [image]'= @ image.jpg部分。

我需要通过我的curl_setopt($ch, CURLOPT_POSTFIELDS)字段进行此项工作?有人能帮助我吗?

回答

0
$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);