PHP code example of hobbily / flysystem-aliyun-oss

1. Go to this page and download the library: Download hobbily/flysystem-aliyun-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/ */

    

hobbily / flysystem-aliyun-oss example snippets


// config/app.php

'providers' => [
    '...',
    Xsilen\Flysystem\AliyunOss\AliyunOssServiceProvider::class,
];

'oss' => [
    'driver'     => 'oss',
    'access_id'  => env('ALIYUN_OSS_ACCESS_KEY_ID'),
    'access_key' => env('ALIYUN_OSS_ACCESS_KEY_SECRET'),
    'bucket'     => env('ALIYUN_OSS_BUCKET_NAME'),
    //使用endpoint来上传oss文件, 如果是OSS内网上传, 刚将OSS内网地址填在此处
    'endpoint'   => env('ALIYUN_OSS_ENDPOINT'),
    'cdnDomain'  => env('ALIYUN_OSS_CDN_DOMAIN'),
    // true to use 'https://' and false to use 'http://'. default is false,
    'ssl'        => true,
    // 如果isCName为true, getUrl会判断cdnDomain是否设定来决定返回的url,如果cdnDomain未设置,则使用endpoint来生成url,否则使用cdn
    // 而且, 上传将会用endpoint来上传, 读取将会用cdnDomain来读取
    'isCName'    => true,
    'prefix'     => env('OSS_PREFIX', ''), // optional
],

    'default' => 'oss'

Storage::disk('oss')->putFile($path, '/local_file_path/1.png', ['mimetype' => 'image/png']);
Storage::disk('oss')->signedDownloadUrl($path, 3600, /*可强制写cdnDomain*/'oss-cn-beijing.aliyuncs.com', true);
Storage::disk('oss')->fullUrl($path, /*可强制写cdnDomain*/'oss-cn-beijing.aliyuncs.com', true);

'interfaces'      => [
    '\Illuminate\Contracts\Filesystem\Filesystem' => Xsilen\Flysystem\AliyunOss\FilesystemAdapter::class,
],