Giter Site home page Giter Site logo

thinkphp-tencent-oss's Introduction

thinkphp6 腾讯云oss

基于 freyo/flysystem-qcloud-cos-v5 轻度封装tp

安装


# thinkphp6
composer require death_satan/thinkphp-tencent-oss ^6.0
# thinkphp8
composer require death_satan/thinkphp-tencent-oss ^8.0

初始化

修改配置 config/filesystem.php 文件


<?php

return [
    // 默认磁盘
    'default' => env('filesystem.driver', 'local'),
    // 磁盘列表
    'disks'   => [
        'local'  => [
            'type' => 'local',
            'root' => app()->getRuntimePath() . 'storage',
        ],
        'public' => [
            // 磁盘类型
            'type'       => 'local',
            // 磁盘路径
            'root'       => app()->getRootPath() . 'public/storage',
            // 磁盘路径对应的外部URL路径
            'url'        => '/storage',
            // 可见性
            'visibility' => 'public',
        ],
        //新增一个阿里云磁盘
        'tencent'=>[
            'type'            => 'Tencent',//设置驱动
            'region'          => 'ap-guangzhou',//设置一个默认的存储桶地域
            'credentials'     => [
                'appId'     => null,//appid
                'secretId'  => 'your-secret-id',//"云 API 密钥 SecretId";
                'secretKey' => 'your-secret-key', //"云 API 密钥 SecretKey";
                'token'     => null,//"临时密钥 token";
            ],
            'timeout'         => 60,//
            'connect_timeout' => 60,//
            'bucket'          => 'your-bucket-name', //设置一个默认的存储桶地域
            'cdn'             => '',//cdn地址
            'scheme'          => 'https', //协议头部,默认为http
            'read_from_cdn'   => false,//
            'cdn_key'         => '',//cdn key
            'encrypt'         => false,//
        ]
        // 更多的磁盘配置信息
    ],
];

使用方法

通过filesystem使用


//通过门面使用
think\facade\Filesystem::disk('tencent')
//在控制器中通过注入使用
class TestControl{

    public function Test(\think\Filesystem $filesystem)
    {
        $aliyun = $filesystem->disk('tencent');
    }
}

文件上传

<?php
namespace app\controller;

use app\BaseController;
use app\Request;
use think\facade\Filesystem;

class Index extends BaseController
{
    public function index(Request $request)
    {
        //获取上传文件
        $file = $request->file('image');
        //通过filesystem进行上传
        $url = Filesystem::disk('tencent')->putFile('images', $file);
        if (!$url) new \exception('上传失败');

        dd('上传成功,文件位置:' . $url);
    }
}

thinkphp-tencent-oss's People

Contributors

zds-s avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.