🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
AccessKeyID: LTAIM4AuYW5hk3P8 AccessKeySecret: 99HDcpi2gUL9sPNnpYx38t0b1U86OD ``` // 上传到青牛云 public function uploader(Request $request) { // 获得上传的文件path $file = $_FILES['file']['tmp_name']; // 获得文件的后缀 $pathInfo = pathinfo($_FILES['file']['name']); $ext = $pathInfo['extension']; // 青牛云配置 $auth = new Auth('Ou8cn0thEfGlsQU-J3t9gqhnPP1df11XP0SwZqwB', '-AwiBAtbVgkvSmhYWjhx2w6ha3KwT0ruLBg6nhqL'); $token = $auth->uploadToken('files'); $key = date('YmdHis') . rand(0, 9999) . '.' . $ext; $uploadMgr = new UploadManager(); $info = $uploadMgr->putFile($token, $key, $file); if ($info) { $data = [ 'path' => 'http://p6am6q3nn.bkt.clouddn.com' . '/' . $key, 'time' => time(), ]; Db::table('tp_img')->insert($data); $json = json_encode(['valid' => 1, 'message' => 'http://p6am6q3nn.bkt.clouddn.com' . '/' . $key]); } else { // 上传失败获取错误信息 $json = json_encode(['valid' => 0, 'message' => '上传失败']); } exit($json); } ``` ``` // 上传到阿里云oss public function uploader(Request $request) { $content = $_FILES['file']['tmp_name'];// 获得上传文件的路径 // 获得文件的后缀 $pathInfo = pathinfo($_FILES['file']['name']); $ext = $pathInfo['extension']; $object = date('YmdHis') . rand(0, 9999) . '.' . $ext;//要生成的文件名 $accessKeyId = "LTAIM4AuYW5hk3P8"; $accessKeySecret = "99HDcpi2gUL9sPNnpYx38t0b1U86OD"; $endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; $bucket = "xingwangifiles"; try { $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint); $info = $ossClient->uploadFile($bucket, $object, $content); if ($info) { $data = [ 'path' => 'http://xingwangifiles.oss-cn-hangzhou.aliyuncs.com/' . $object, 'time' => time(), ]; Db::table('tp_img')->insert($data); $json = json_encode(['valid' => 1, 'message' => 'http://xingwangifiles.oss-cn-hangzhou.aliyuncs.com/' . $object ,'success'=>'阿里云oss图片上传成功,查看地址:'.'http://xingwangifiles.oss-cn-hangzhou.aliyuncs.com/' . $object]); } else { // 上传失败获取错误信息 $json = json_encode(['valid' => 0, 'message' => '上传失败']); } exit($json); } catch (OssException $e) { print $e->getMessage(); } } ```