oss+ laravel自带的文件上传

依赖:

laravel 5.5 以上自动服务发现

composer require panwenbin/laravel-aliyunoss

部署:

// config/filesystems.php
'default' => env('FILESYSTEM_DRIVER', 'oss'), // 缺省驱动改为oss
...
'disks' => [
    ...
    // 增加oss配置段
    'oss' => [
        'driver'     => 'oss',
        'access_id'  => env('OSS_ACCESS_ID','your id'),
        'access_key' => env('OSS_ACCESS_KEY','your key'),
        'bucket'     => env('OSS_BUCKET','your bucket'),
        'endpoint'   => env('OSS_ENDPOINT','your endpoint'),
        'prefix'     => env('OSS_PREFIX', ''), // optional
        'is_cname'   => env('OSS_IS_CNAME', ''), // optional
    ],
]

使用:


         $pic= $request->file('img');
        
         $time = time();
         $path = '/amazondev/';

         $name =$time.rand(1000,9999).$pic->getClientOriginalName();

         $pic->storePubliclyAs('/amazondev/', $name, ['disk' => 'oss']);

         $res_path = 'https://liaosp-public.oss-cn-beijing.aliyuncs.com'.$path.$name;

         return $res_path;
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页