zoukankan      html  css  js  c++  java
  • PHP中使用CURL模拟文件上传实例

    调用实例:

    该方法将本地的E盘文件test.doc上传到接口服务器上的 uploadFile方法中,uploadFile会对上传的文件做进一步处理。

    若你想自己对上传的文件做操作,将接口uploadFile改为自己写好的方法就行了。

    CURL方法如下:

    public function curl_request($url, $post_data,$is_post = true){
            //初始化
            $curl = curl_init();
            //设置抓取的url
            curl_setopt($curl, CURLOPT_URL, $url);
            //设置头文件的信息作为数据流输出
            curl_setopt($curl, CURLOPT_HEADER, 0);
            //设置获取的信息以文件流的形式返回,而不是直接输出。
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    
            if($is_post){
                //设置post方式提交
                curl_setopt($curl, CURLOPT_POST, 1);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
            }
    
    
            //执行命令
            $response = curl_exec($curl);
            //报错
            $error = curl_error($curl);
            //关闭URL请求
            curl_close($curl);
            //显示获得的数据
            /*print_r($response);
            print_r($error);
            die;*/
            return $response;
        }
  • 相关阅读:
    判断闰年
    CaesarCode
    substring
    configure: error: Cannot use an external APR with the bundled APR-util
    字符串处理487-3279
    git分支管理
    git解决冲突
    git 分支的创建和切换
    nginx与php-fpm原理
    git 远程仓库与本地项目关联
  • 原文地址:https://www.cnblogs.com/crystaltu/p/6933167.html
Copyright © 2011-2022 走看看