thinkphp6 簡單三步整合七牛雲上傳,整合tp6七牛雲filesystem擴展


thinkphp6整合文件上傳,七牛雲

composer下載包

# -vvv 可以試試的看到require進度
composer require  death_satan/think-qiniu-storage -vvv

編輯 項目config目錄下的filesystem.php文件

<?php

use think\facade\Env;

return [
    // 默認磁盤
    'default' => Env::get('filesystem.driver', 'local'),
    // 磁盤列表
    'disks'   => [
        'local'  => [
            'type' => 'local',
            'root' => app()->getRuntimePath() . 'storage',
        ],
        'public' => [
            // 磁盤類型
            'type'       => 'local',
            // 磁盤路徑
            'root'       => app()->getRootPath() . 'public/storage',
            // 磁盤路徑對應的外部URL路徑
            'url'        => '/storage',
            // 可見性
            'visibility' => 'public',
        ],
         //newly added
        'qiniu'=>[
           'type'=>'qiniu',
           'accessKey'=>'your accessKey',//你的accessKey
           'secretKey'=>'your secretKey',//你的secretKey
           'bucket'=>'your qiniu bucket name',//你的存儲空間名
           'domain'=>'your qiniu bind domain' //你的七牛雲加速域名
        ]   
        // 更多的磁盤配置信息
    ],
];

配置完后在控制器中使用

<?php
namespace app\controller;

use app\BaseController;

class Index extends BaseController
{
    public function index()
    {
        //獲取上傳文件
        $image = $this->request->file('image');
        //獲取上傳后的文件路徑
        $qiniu_file = \think\facade\Filesystem::disk('qiniu')->putFile('image',$image);
        dd($qiniu_file);
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM