doesBucketExist(self::$storageName)) self::$auth->createBucket(self::$storageName,self::$auth::OSS_ACL_TYPE_PUBLIC_READ_WRITE); } return self::$auth; } /** * TODO 文件上传 名称 * @param string $filename * @return string */ public static function uploadImage($filename = 'image'){ $request = app('request'); $file = $request->file($filename); $filePath = $file->getRealPath(); $ext = pathinfo($file->getInfo('name'), PATHINFO_EXTENSION); $key = substr(md5($file->getRealPath()) , 0, 5). date('YmdHis') . rand(0, 9999) . '.' . $ext; try{ self::autoInfo(); return self::$auth->uploadFile(self::$storageName,$key,$filePath); }catch (OssException $e){ return $e->getMessage(); } } /** * TODO 文件上传 内容 * @param $key * @param $content * @return string */ public static function uploadImageStream($key, $content){ try{ self::autoInfo(); return self::$auth->putObject(self::$storageName,$key,$content); }catch (OssException $e){ return $e->getMessage(); } } /** * TODO 删除资源 * @param $key * @return mixed */ public static function delete($key){ try { self::autoInfo(); return self::$auth->deleteObject(self::$storageName,$key); } catch (OssException $e) { return $e->getMessage(); } } }