Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下 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)领域什么才能使这项工作?有人可以帮我吗?
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);