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 = array('path' =>new \CURLFile($_FILES['myateam_image']['tmp_name']),'img_type'=>'png');
        //$data = array('path' => ($_FILES['myateam_image']['tmp_name']),'img_type'=>'png');
            //'myateam_image'=>new \CURLFile($_FILES['myateam_image']['tmp_name']),  //图片成功暂时去掉       
        curl_setopt($ch,CURLOPT_URL,$url);  
        curl_setopt($ch,CURLOPT_POST,true);  
        curl_setopt($ch,CURLOPT_POSTFIELDS, $data);  
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);  

        $result = curl_exec($ch);
        curl_close($ch);

        echo $result;

    }

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

    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  =     ''; // 设置附件上传(子)目录
$upload->saveExt   =     'png'; // 上传文件的保存后缀,不设置的话使用原文件后缀 if(!$upload->upload()) {// 上传错误提示错误信息 //$this->error(); $this->error($upload->getError()); }else{// 上传成功 获取上传文件信息 foreach($info as $file){ echo $file['savepath'].$file['savename']; } } }

 

posted @ 2017-07-07 14:46  ready_dream  阅读(918)  评论(0编辑  收藏  举报