1、composer加载oss插件

composer require aliyuncs/oss-sdk-php

 

 

 

2、更改config配置

图片上传阿里云oss  数据存入redis List

 

 

//控制器代码如下

图片上传阿里云oss  数据存入redis List

 

 

 public function aliyun($category='',$isunlink=false,$bucket="phpchai"){
        $file=$_FILES;
        $savePath=$file['file']['name'];//文件名称
        $accessKeyId = config('aliyun_oss.accessKeyId');//去阿里云后台获取秘钥
        $accessKeySecret = config('aliyun_oss.accessKeySecret');//去阿里云后台获取秘钥
        $endpoint = config('aliyun_oss.endpoint');//你的阿里云OSS地址
        $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
        //   判断bucketname是否存在,不存在就去创建
        if( !$ossClient->doesBucketExist($bucket)){
            $ossClient->createBucket($bucket);
        }
        $category=empty($category)?$bucket:$category;
        $object = $category.'/'.$savePath;//想要保存文件的名称
        $file = 'E:/img/'.$savePath;//文件路径,必须是本地的。
        try{
            $ossClient->uploadFile($bucket,$object,$file);
            if ($isunlink==true){
                unlink($file);
            }
        }catch (OssException $e){
            $e->getErrorMessage();
        }
        $oss=config('aliyun_oss.url');
        $img=$oss.$object;
      //  $this->addShop($img);
        return $oss.$object;
    }

上传至阿里云
图片上传阿里云oss  数据存入redis List

 


 

 
   $redis = new \Redis();
                $redis->connect('127.0.0.1', '6379');
                $value = ['uid' => $uid, 'community_id' => $community_id, 'faceimg' => $faceimg];
                $val = json_encode($value);
                $redis->lPush('face_queue', $val);

 



相关文章:

  • 2022-12-23
  • 2021-12-18
  • 2021-12-18
  • 2021-12-18
  • 2021-12-18
  • 2021-12-18
  • 2021-09-17
  • 2021-06-23
猜你喜欢
  • 2022-12-23
  • 2021-12-18
  • 2021-12-18
  • 2021-12-18
  • 2021-05-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案