zoukankan      html  css  js  c++  java
  • php各个版本curl上传文件的兼容实现

     // 以POST方式提交数据
        public function post_data($url, $param, $is_file = false, $return_array = true) {
           ........
            $ch = curl_init ();
            curl_setopt ( $ch, CURLOPT_URL, $url );
            curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
            curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
            curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
            curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
            curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)' );
            curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
            curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 );
    
            curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
            if($is_file){
                if(version_compare(phpversion(),'5.6')>=0){
                    if(version_compare(phpversion(),'7')>=0){
                        $param['media'] = new CURLFile(ltrim($param['media'], '@'));
                    }else{
                        curl_setopt ( $ch, CURLOPT_SAFE_UPLOAD, false);
                    }
                }
            }
            curl_setopt ( $ch, CURLOPT_POSTFIELDS, $param );
    
            $res = curl_exec ( $ch );
    
            curl_close ( $ch );
    
           .......
    
            return $res;
        }
    

      

  • 相关阅读:
    问题集
    第04次作业-树
    06-图
    05-查找
    04-树
    03-栈和队列
    02-线性表
    01-抽象数据类型
    C语言--总结报告
    C语言--函数嵌套
  • 原文地址:https://www.cnblogs.com/tu6ge/p/5956321.html
Copyright © 2011-2022 走看看