laravel中使用七牛云存储

1.1packagist官网

很好用
链接

1.2composer安装:

composer require overtrue/laravel-filesystem-qiniu

1.3安装之后的配置:

安装库之后,Overtrue\LaravelFilesystem\Qiniu\QiniuStorageServiceProvider在config/app.php文件中注册:

'providers' => [
    // Other service providers...
    Overtrue\LaravelFilesystem\Qiniu\QiniuStorageServiceProvider::class,
],

1.4:在config/filesystems.php中配置:

<?php

return [
   'disks' => [
        //...
        'qiniu' => [
           'driver'     => 'qiniu',
           'access_key' => env('QINIU_ACCESS_KEY', 'xxxxxxxxxxxxxxxx'),
           'secret_key' => env('QINIU_SECRET_KEY', 'xxxxxxxxxxxxxxxx'),
           'bucket'     => env('QINIU_BUCKET', 'test'),
           'domain'     => env('QINIU_DOMAIN', 'xxx.clouddn.com'), // or host: https://xxxx.clouddn.com
        ],
        //...
    ]
];

access_key&&secret_key位置:

bucket==你的bucket名称,domain如下图

1.5:主要展示控制器代码:

 public function upload(Request $request)
    {
        $file = $request->file('file');
        $path = $file->getRealPath();#得到文件的临时地址
        $name = $file->getClientOriginalName();#得到文件的名称
        $disk = \Storage::disk('qiniu');
        $disk->put($name, $path);
    }

猜你喜欢

转载自www.cnblogs.com/yaoliuyang/p/12819912.html
今日推荐