Rumah  >  Artikel  >  pembangunan bahagian belakang  >  PHP使用curl模拟post上传及接收文件的方法,_PHP教程

PHP使用curl模拟post上传及接收文件的方法,_PHP教程

WBOY
WBOYasal
2016-07-12 08:57:54784semak imbas

PHP使用curl模拟post上传及接收文件的方法,

本文实例讲述了PHP使用curl模拟post上传及接收文件的方法。分享给大家供大家参考,具体如下:

public function Action_Upload(){
     $this->path_config();
    exit();
    $furl="@d:\develop\JMFrameworkWithDemo.rar";
    $url= "http://localhost/DemoIndex/curl_pos/";
    $this->upload_file_to_cdn($furl, $url);
}
public function upload_file_to_cdn($furl,$url){
    //  初始化
    $ch = curl_init();
    // 要上传的本地文件地址"@F:/xampp/php/php.ini"上传时候,上传路径前面要有@符号
    $post_data = array (
      "upload" => $furl
    );
    //print_r($post_data);
    //CURLOPT_URL 是指提交到哪里?相当于表单里的“action”指定的路径
    //$url = "http://localhost/DemoIndex/curl_pos/";
    //  设置变量
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);//执行结果是否被返回,0是返回,1是不返回
    curl_setopt($ch, CURLOPT_HEADER, 0);//参数设置,是否显示头部信息,1为显示,0为不显示
    //伪造网页来源地址,伪造来自百度的表单提交
    curl_setopt($ch, CURLOPT_REFERER, "http://www.baidu.com");
    //表单数据,是正规的表单设置值为非0
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 100);//设置curl执行超时时间最大是多少
    //使用数组提供post数据时,CURL组件大概是为了兼容@filename这种上传文件的写法,
    //默认把content_type设为了multipart/form-data。虽然对于大多数web服务器并
    //没有影响,但是还是有少部分服务器不兼容。本文得出的结论是,在没有需要上传文件的
    //情况下,尽量对post提交的数据进行http_build_query,然后发送出去,能实现更好的兼容性,更小的请求数据包。
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    //   执行并获取结果
    curl_exec($ch);
    if(curl_exec($ch) === FALSE)
    {
      echo "<br/>"," cUrl Error:".curl_error($ch);
    }
    //  释放cURL句柄
    curl_close($ch);
    echo "aaa45";
}
function action_curl_pos(){
    var_dump($_FILES);
    $aa= move_uploaded_file($_FILES["upload"]["tmp_name"], "/wamp/tools/1.rar");
    if($aa){
      echo "11";
    }
}

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php curl用法总结》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

您可能感兴趣的文章:

  • php curl模拟post请求和提交多维数组的示例代码
  • PHP基于CURL进行POST数据上传实例
  • PHP函数分享之curl方式取得数据、模拟登陆、POST数据
  • php curl post 时出现的问题解决
  • php curl模拟post提交数据示例
  • php curl模拟post请求小实例
  • PHP中使用cURL实现Get和Post请求的方法
  • PHP下使用CURL方式POST数据至API接口的代码
  • php中使用Curl、socket、file_get_contents三种方法POST提交数据
  • PHP的cURL库功能简介 抓取网页、POST数据及其他
  • PHP CURL模拟GET及POST函数代码
  • php的curl实现get和post的代码

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1106116.htmlTechArticlePHP使用curl模拟post上传及接收文件的方法, 本文实例讲述了PHP使用curl模拟post上传及接收文件的方法。分享给大家供大家参考,具体如下:...
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn