zoukankan      html  css  js  c++  java
  • 图片上传阿里云oss 数据存入redis List

    1、composer加载oss插件

    composer require aliyuncs/oss-sdk-php

    2、更改config配置

    //控制器代码如下

     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;
        }

    上传至阿里云
    
    
    
     
       $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);
    
    
    


  • 相关阅读:
    react-umi 光速上手
    vue 和 react 的区别
    SP12323 NAKANJ
    UVA439 骑士的移动
    NOI 2020 Vlog
    二叉查找树
    可持久化线段树(主席树)
    权值线段树
    YNOI2020 游记
    《四月是你的谎言》语录
  • 原文地址:https://www.cnblogs.com/chaihtml/p/12083631.html
Copyright © 2011-2022 走看看