• 七牛云,php


    composer require qiniu/php-sdk
    

    工具类

    <?php
    /**
     * 七牛云,工具类
     */
    
    namespace CommonUtil;
    use QiniuConfig;
    use QiniuStorageBucketManager;
    use QiniuStorageUploadManager;
    use QiniuAuth;
    
    class QiniuUtil extends CommonUtil {
        protected $accessKey = '';
        protected $secretKey = '';
        public function __construct()
        {
            parent::__construct();
            $this->accessKey = C('QINIU.ACCESS_KEY');
            $this->secretKey = C('QINIU.SECRET_KEY');
        }
    
        /**
         * @param $file
         * @param $key
         * @param $bucket
         * @return false|mixed
         */
        public function up($file, $key, $bucket = '') {
            if (!$bucket) {
                $bucket =  C('QINIU.BUCKET');
            }
            $uploadMgr = new UploadManager();
            $auth = new Auth($this->accessKey, $this->secretKey);
            $token = $auth->uploadToken($bucket);
            list($ret, $error) = $uploadMgr->put($token, $key, file_get_contents($file));
            if (!$error) {
                return $ret;
            } else {
                return false;
            }
        }
    
        /**
         * 删除资源
         * @param $key
         * @param $bucket
         * @return bool
         */
        public function delKey($key,$bucket = '') {
            if (!$bucket) {
                $bucket =  C('QINIU.BUCKET');
            }
            $auth = new Auth($this->accessKey, $this->secretKey);
            $config = new Config();
            $bucketManager = new BucketManager($auth, $config);
            $err = $bucketManager->delete($bucket, $key);
            if (!$err) {
                return true;
            } else {
                return false;
            }
        }
    
        /**
         * 统计资源信息
         * @param $key
         * @param $bucket
         * @return bool
         */
        public function statKey($key,$bucket = '') {
            if (!$bucket) {
                $bucket =  C('QINIU.BUCKET');
            }
            $auth = new Auth($this->accessKey, $this->secretKey);
            $config = new Config();
            $bucketManager = new BucketManager($auth, $config);
            list($ret, $err) = $bucketManager->stat($bucket, $key);
            if ($err != null) {
                return false;
            } else {
                return $ret['fsize'];
            }
        }
    }
    
  • 相关阅读:
    mysql5.7 tar包安装
    jpa2.0以上findOne和getOne的区别
    终端设置代理
    virtualbox EFI安装Archlinux
    无法在web.xml或使用此应用程序部署的jar文件中解析绝对uri:[http://java.sun.com/jsp/jstl/core]
    代理模式笔记
    Mybatis详细的执行流程
    javaweb超市管理系统demo
    CF1409F Subsequences of Length Two
    1002: [FJOI2007]轮状病毒 基尔霍夫矩阵
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/15043479.html
Copyright © 2020-2023  润新知