php – 是否可以使用cURL使用POST流上传文件?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 是否可以使用cURL使用POST流上传文件?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
或者 PHP不允许这样做?我已经读过可以使用PUT,但服务器只能使用POST.
是的,可以使用cURL使用POST文件上传上传文件.这是认设置,您需要提供要以字符串形式流式传输的文件文件名.
// URL on which we have to post data
$url = "http://localhost/tutorials/post_action.PHP";
// Any other field you might want to catch
$post_data['name'] = "khan";
// File you want to upload/post
$post_data['file'] = "@c:/LOGs.log";

// InITialize cURL
$ch = curl_init();
// Set URL on which you want to post the Form and/or data
curl_setopt($ch,CURLOPT_URL,$url);
// Data+Files to be posted
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
// Pass TRUE or 1 if you want to wait for and catch the response against the request made
curl_setopt($ch,CURLOPT_RETURNtransfer,1);
// For Debug mode; shows up any error encountered during the operation
curl_setopt($ch,CURLOPT_VERBOSE,1);
// Execute the request
$response = curl_exec($ch);

// Just for debug: to see response
echo $response;

除了该方法之外,无法使用cURL使用POST方法上传文件.

脚本宝典总结

以上是脚本宝典为你收集整理的php – 是否可以使用cURL使用POST流上传文件?全部内容,希望文章能够帮你解决php – 是否可以使用cURL使用POST流上传文件?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。