加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 18:10:22 所属栏目:PHP教程 来源:网络整理
导读:或者 PHP不允许这样做?我已经读过可以使用PUT,但服务器只能使用POST. 是的,可以使用cURL使用POST文件上传来上传文件.这是默认设置,您需要提供要以字符串形式流式传输的文件的文件名. // URL on which we have to post data$url = "http://localhost/tutoria
或者 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方法流上传文件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读