首页 > 作文

curl put方式上传文件

更新时间:2023-04-07 06:35:51 阅读: 评论:0

发送端

 1 <?php 2  3 function curlput($desturl, $sourcefiledir, $headerarr = array(), $timeout = 10) 4 { 5     $ch = curl_init(); //初始化curl 6     curl_topt($ch, curlopt_returntransfer, true); //返回字符串,而不直接输出 7     curl_topt($ch, curlopt_url, $desturl); //设置put到的url 8     curl_topt($ch, curlopt_httpheader, $h财务管理专业课程eaderarr); 9     curl_topt($ch, curlopt_timeout, $timeout);10     curl_topt($ch, curlopt_ssl_verifypeer, fal); //不验证对等证书11     cu汽车服务与营销rl_topt($ch, curlopt_ssl_verifyhost, 0); //不检查服务器ssl证书12 13     curl_topt($ch, curlopt_put, true); //设置为put请求14     curl_topt($ch, curlopt_infile, fopen($sourcefiledir, 'rb')); //设置资源句柄15     curl_topt($ch, curlopt_infilesize, filesize($sourcefiledir));16 17     $respon = curl_exec($ch);18     if ($error = curl_error($ch))19     {20         $bkarr =  array(21             'code' => 0,22             'msg' => $error,23         );24     }25     el26     {27         $bkarr =  array(28             'code' => 1,29             'msg' => 'ok',30             'resp' => $respon,31         );32     }33 34     curl_clo($ch); // 关闭 curl 释放资源35 36     rednf 男气功turn $bkarr;37 }38 39 $desturl = 'http://www.songjm.com/http_put_save.php';40 $sourcefiledir = 'ast/pic.png';41 $headerarr = array(42     'filename:newname.png',43 );44 45 $bkjson = curlput($desturl, $sourcefiledir, $headerarr);46 $bkarr = json_decode($bkjson, true);47 echo "<pre>";48 print_r($bkarr);49 die;

接收端

 1 <?php 2  3 if ($_rver['request_method'] != 'put') 4 { 5     $bkmsg = array( 6         'code' => 宋江简介-1, 7         'msg' => 'not put', 8     ); 9     echo json_encode($bkmsg);10     exit();11 }12 13 $filename = $_rver['http_filename'];14 15 $fi漂亮的反义词lesavedir = 'upload/';16 $newfile = $filesavedir.$filename;17 18 $handletosave = fopen($newfile,'wb+'); 19 $handlesource = fopen('php://input','rb');20 21 while (!feof($handlesource))22 {23     fwrite($handletosave, fread($handlesource, 1024));24 }25 26 fclo($handletosave);27 fclo($handlesource);28 29 $bkmsg = array(30     'code' => 1,31     'msg' => 'ok',32 );33 echo json_encode($bkmsg);34 exit();

本文发布于:2023-04-07 06:34:52,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/9c9db4e8b79ac214036b1cfc5ddb6efc.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:curl put方式上传文件.doc

本文 PDF 下载地址:curl put方式上传文件.pdf

标签:证书   反义词   句柄   资源
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图