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


  • 相关阅读:
    python Matplotlib数据可视化神器安装与基本应用
    linux笔记
    appium自动化环境搭建
    C#实现局域网聊天 通讯 Socket TCP 多人
    layui 关闭弹出层方法
    allure生成漂亮的测试报告
    python内置测试框架unittest
    Python安全编程
    Python Web自动化测试
    Docker从入门到放弃
  • 原文地址:https://www.cnblogs.com/chaihtml/p/12083631.html
Copyright © 2011-2022 走看看