php - 如何使用 php-curl 发布存储在本地的二进制文件?

标签 php post curl

我希望使用 php-curl 发出以下 curl 请求:

curl "http://www.example.com/" -F "file=@foo.ext"

假设 foo.ext,我需要如何在 PHP 中进行设置(使用 curl_init、_setopt 等)住在我发出请求的机器上?

最佳答案

你会用

curl_setopt($curl_handle, CURLOPT_POST, TRUE);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, array('file' => '@foo.ext'));

加上您需要的任何选项。相关文档:http://php.net/curl_setopt

关于php - 如何使用 php-curl 发布存储在本地的二进制文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10322646/

相关文章:

javascript - Ajax 数据发布无法通过发布的 url

python - 链接回之前访问过的表单

ios - iOS 上 GitHub API 的身份验证错误

php - 如何在 PHP 中获取关联数组中的前 n 个键?

php - codeigniter 后端和前端的路由配置

php - 我如何获取从一个页面到另一个重定向页面的数组ID

linux - 使用 sed 将 Curl 信息导出到文件

php - 如何在 'RequestPermissions' 操作中通过 CURL 将 HTTP header 和 url 变量发送到 Paypal?

php - 收到警告 "Header may not contain more than a single header, new line detected"

javascript - PHP json_encode 编码函数