zoukankan      html  css  js  c++  java
  • 七牛云,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'];
            }
        }
    }
    
  • 相关阅读:
    Web开发中需要了解的东西
    Javascript:谈谈JS的全局变量跟局部变量
    多角度看.NET面试题
    java http大文件断点续传上传方法
    java http大文件断点续传上传问题
    java http大文件断点续传上传功能
    java http大文件断点续传上传解决方案
    java http大文件断点续传上传实例
    java http大文件断点续传上传示例
    java http大文件断点续传上传源代码
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/15043479.html
Copyright © 2011-2022 走看看