PHP code example of back / laravel-filesystem-obs

1. Go to this page and download the library: Download back/laravel-filesystem-obs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

back / laravel-filesystem-obs example snippets


'providers' => [
    // Other service providers...
    Back\LaravelObs\HuaweiObsServiceProvider::class,
],



return [
   'disks' => [
        //...
        'obs' => [
            'driver' => 'obs',
            'key' => env('OBS_KEY', ''),
            'secret' => env('OBS_SECRET', ''),
            'bucket' => env('OBS_BUCKET', ''),
            'endpoint' => env('OBS_ENDPOINT', ''),
            'cdn_domain' => env('OBS_CDN_DOMAIN', false),
            'options' => [], // 其他选项就看华为云初始化客户端参数
        ]
        //...
    ]
];

$disk = Storage::disk('obs');

// 上传
$disk->put('avatars/example.jpg', $fileContents);

// 检查文件是否存在
$exists = $disk->has('avatars/example.jpg');

// 获取文件修改时间
$time = $disk->lastModified('avatars/example.jpg');

// 拷贝文件
$disk->copy('avatars/example.jpg', 'avatars/example-copy.jpg');

// 移动文件也可改名
$disk->move('avatars/example-copy.jpg', 'avatars/example-move.jpg');

// 获取文件内容
$contents = $disk->read('avatars/example-move.jpg');