//引入类库,可到官网下载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'])); } }