Blogger Information
Blog 10
fans 1
comment 0
visits 13022
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkPHP调用七牛云上传图片
GrMax的博客
Original
1906 people have browsed it
//引入类库,可到官网下载sdk
Vendor('sdk.autoload'); 
use \Qiniu\Auth;
use \Qiniu\Storage\UploadManager;
use \Qiniu\Storage\BucketManager;

然后就是直接干啊

  //常规图片上传
    public function uploadPic(){
             $auth = new Auth($accessKey, $secretKey);
            // 生成上传Token
             $token = $auth->uploadToken($bucket);//空间
             $uploadMgr = new UploadManager();
             $tempArr=explode('/',$saveFile);
             $filename=array_pop($tempArr);
             $filePath = $save_path . $saveFile;
             $key = $filename;
             list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
             if ($err !== null) {
                  $this->ajaxReturn(array('ret'=>0,'msg'=>'云储存失败,请联系客服','code'=>$err));
                 } else {
                            $ret['key'] = $NIU_URL.'/'.$ret['key'];//拼接返回地址
                            unlink($save_path . $saveFile);//删除本地文件
                            $this->ajaxReturn(array('ret'=>1,'saveFile'=>$ret['key']));
                   }
                   
    }


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post