PHP code example of vartruexuan / yii-filesystem-cos

1. Go to this page and download the library: Download vartruexuan/yii-filesystem-cos 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/ */

    

vartruexuan / yii-filesystem-cos example snippets


// 加入配置组件
'components' => [
    'cos' => [
        'class' => 'Vartruexuan\Yii2\Filesystem\Cos\Filesystem',
        // 配置
        'region' => 'gz',
        'appId' => '1272757004',
        'secretId' => 'AKIDd5HCSPDanlU1ILnzwc2sSmpcIqTY',
        'secretKey' => '58kxufPxEiiSWIbeuUqxsYzDB3gAPVLwI',
        'token' => null,
        'timeout' => 60,
        'connect_timeout' => 60,
        'bucket' => 'bucket-1272757004',
        'cdn' => 'https://bucket-1272757004.file.myqcloud.com',
        'scheme' => 'https',
        'read_from_cdn' => false,
        'cdn_key' => '',
        'encrypt' => false,
    ],
],
   
bool Yii::$app->cos->->write('file.md', 'contents');
bool Yii::$app->cos->->writeStream('file.md', fopen('path/to/your/local/file.jpg', 'r'));
bool Yii::$app->cos->->update('file.md', 'new contents');
bool Yii::$app->cos->->updateStram('file.md', fopen('path/to/your/local/file.jpg', 'r'));
bool Yii::$app->cos->->rename('foo.md', 'bar.md');
bool Yii::$app->cos->->copy('foo.md', 'foo2.md');
bool Yii::$app->cos->->delete('file.md');
bool Yii::$app->cos->->has('file.md');
string|false Yii::$app->cos->->read('file.md');
array Yii::$app->cos->->listContents();
array Yii::$app->cos->->getMetadata('file.md');
int Yii::$app->cos->->getSize('file.md');
string Yii::$app->cos->->getUrl('file.md'); 
string Yii::$app->cos->->getTemporaryUrl('file.md', date_create('2018-12-31 18:12:31')); 
string Yii::$app->cos->->getMimetype('file.md');
int Yii::$app->cos->->getTimestamp('file.md');
string Yii::$app->cos->->getVisibility('file.md');
bool Yii::$app->cos->->setVisibility('file.md', 'public'); //or 'private', 'default'
// ...