2013-01-16 30 views
1

我有簡單的PHP腳本。殼牌捲毛請求

$url = 'http://test.com/api/images/products/33'; 
$image_path = '/srv/images/some.jpg'; 
$key = 'qwerty'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, true); 
//curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image 
curl_setopt($ch, CURLOPT_USERPWD, $key.':'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path)); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch); 
curl_close($ch); 

該腳本運行良好。我想將此代碼轉換爲簡單的curl shell命令。

我試圖

curl -v -X POST -d [email protected]/srv/images/some.jpg \ 
http://[email protected]/api/images/products/33 

但錯誤發生。哪裏不對?

+1

'/路徑/到/ PHP /路徑/到/你/ script.php' ;-) –

+1

「但發生錯誤」 - **什麼**錯誤? – Quentin

回答

0

你應該使用-F(用於multipart/form-data),而不是-d(使用application/x-www-form-urlencoded):

所以這應該工作:

curl -v -X POST -F [email protected]/srv/images/some.jpg http://[email protected]/api/images/products/33