PHP code example of lonelywalkersource / laravel-filesystem-oss

1. Go to this page and download the library: Download lonelywalkersource/laravel-filesystem-oss 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/ */

    

lonelywalkersource / laravel-filesystem-oss example snippets


'disks' => [
    // ...
    'oss' => [
        // ── Required ────────────────────────────────────
        'driver'      => 'oss',

        // Alibaba Cloud AccessKey ID (alias: 'key')
        'access_key'  => env('OSS_ACCESS_KEY'),

        // Alibaba Cloud AccessKey Secret (alias: 'secret')
        'secret_key'  => env('OSS_SECRET_KEY'),

        // OSS endpoint, e.g. oss-cn-hangzhou.aliyuncs.com
        'endpoint'    => env('OSS_ENDPOINT', 'oss-cn-hangzhou.aliyuncs.com'),

        // Bucket name
        'bucket'      => env('OSS_BUCKET'),

        // ── Optional ────────────────────────────────────

        // Region (e.g. cn-hangzhou) — �� Flysystem Options ───────────────────────────

        // Whether to throw exceptions. Default: true
        'throw'       => true,

        // ── OssClient Extra Options ─────────────────────
        // Any key not listed above is passed directly to the OssClient constructor.
        // Valid OssClient options 

// Store a file
Storage::disk('oss')->put('path/to/file.txt', 'Hello OSS');

// Get the URL
$url = Storage::disk('oss')->url('path/to/file.txt');

// Temporary URL
$tempUrl = Storage::disk('oss')->temporaryUrl('path/to/file.txt', now()->addHour());

// Direct access to adapter
$adapter = Storage::disk('oss')->getAdapter();
$postPolicy = $adapter->generatePostPolicy([
    'expire' => 1800,
    'prefix' => 'uploads/',
]);

'oss' => [
    'driver'      => 'oss',
    'access_key'  => env('OSS_ACCESS_KEY'),
    'secret_key'  => env('OSS_SECRET_KEY'),
    'endpoint'    => env('OSS_ENDPOINT'),
    'bucket'      => env('OSS_BUCKET'),
    'region'      => env('OSS_REGION'),
    'buckets'     => [
        'images' => [
            'bucket'   => env('OSS_BUCKET_IMAGES'),
            'endpoint' => env('OSS_ENDPOINT_IMAGES'),
        ],
    ],
],

// Access secondary bucket via the adapter
$adapter = Storage::disk('oss')->getAdapter();
$imagesAdapter = $adapter->bucket('images');