I have the following cURL command, to add an image to my server, which works just fine:
curl -i -X POST -u user:pw -F 'post[image]'=@image.jpg http://domain.com/post.json
Now I want to make this work in PHP. I seem to get everything working, except for the 'post[image]'=@image.jpg part.
What do I need to pass to my curl_setopt($ch, CURLOPT_POSTFIELDS)
field make this work? Can someone help me out here?
$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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.