v2-df.jpg

namespace app\controller;

use OSS\OssClient;

class Oss {

    private static _instance;

    private function __construct() {

    }

    private function __clone() {

    }

    /**

     * 获取一个OssClient实例

     * @return null|OssClient

     */

    public static function getInstance() {

        if (!(self::_instance instanceof OssClient)) {

            try {

                self::_instance = new OssClient(env('oss.access_key_id'), env('oss.access_key_secret'), env('oss.endpoint'), false);

            } catch (OssExceptione) {

                printf(__FUNCTION__ . "creating OssClient instance: FAILED\n");

                printf(e->getMessage() . "\n");

                return null;

            }

        }

        return self::_instance;

    }

    /**

     * 获取bucket

     * @return string

     */

    public static function getBucketName()

    {

        return env('oss.bucket');

    }

}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code