首页 > 代码库 > thinkphp中curl接受图片然后上传到数据库

thinkphp中curl接受图片然后上传到数据库

    public function tuisongfile(){
        $this->display();
    }

    public function wpull(){

        header(‘content-type:text/html;charset=utf8‘);
        
        $url = "http://localhost/baoanwap/index.php/Home/Index/wpull";
        
        //var_dump($_FILES);
        //var_dump($_FILES[‘myateam_image‘][‘tmp_name‘]);exit;
        $ch = curl_init();
        $data = http://www.mamicode.com/array(‘path‘ =>new /CURLFile($_FILES[‘myateam_image‘][‘tmp_name‘]),‘img_type‘=>‘png‘);>

 上面接受到图片,然后发送到另一个服务器

    public function wpull(){


        $tmpname = $_FILES["path"]["tmp_name"];
        //print_r($_FILES);exit();
        //echo ‘===file upload info:‘;
        //print_r($_FILES[‘path‘][‘tmp_name‘]);exit();
        //move_uploaded_file($_FILES["path"]["tmp_name"],"./Public/ceshi/");


        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        //$upload->exts    =     array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘);// 设置附件上传类型
        $upload->rootPath  =     ‘./Public/ceshi/‘; // 设置附件上传根目录
        $upload->savePath  =     ‘‘; // 设置附件上传(子)目录
        
        if(!$upload->upload()) {// 上传错误提示错误信息
            //$this->error();
           
            $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息

            foreach($info as $file){
                echo $file[‘savepath‘].$file[‘savename‘];
            }
        }
        



    }

 

thinkphp中curl接受图片然后上传到数据库