PHP code example of cdcchen / yii2-cloud-storage

1. Go to this page and download the library: Download cdcchen/yii2-cloud-storage 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/ */

    

cdcchen / yii2-cloud-storage example snippets


'storage' => [
    'class' => 'cdcchen\yii\cloudstorage\UpYunStorage',
    'isImageBucket' => true,
    'endpoint' => 'v2.api.upyun.com',
    'bucket' => 'test',
    'username' => 'test',
    'password' => '123123',
    'domain' => 'http://test.b0.upaiyun.com',
    'autoGenerateFilename' => true,
    'pathFormat' => '{year}/{month}/{day}',
    'filenameFormat' => '{timestamp}-{uniqid}',
]

/* @var \cdcchen\yii\cloudstorage\Storage $storage */
$storage = Yii::$app->get('storage');

$filename = Yii::getAlias('@runtime/chen.jpg');
$info = $storage->write($filename);


$filename = Yii::getAlias('@runtime/chen.jpg');
$filepath = '/test/a.jpg';
$info = $storage->write($filename, $filepath);


Array
(
    [url] => http://test.b0.upaiyun.com/2016/05/04/1462332949-57296e153ab67.jpeg
    [file] => /avatar/chendong/2016/05/04/1462332949-57296e153ab67.jpeg
    [path] => /avatar/chendong/2016/05/04
    [name] => 1462332949-57296e153ab67.jpeg
    [width] => 479
    [height] => 555
    [type] => JPEG
    [frames] => 1
)

Array
(
    [url] => http://test.b0.upaiyun.com/avatar/2016/05/04/1462333056-57296e80bbfa2.doc
    [file] => /avatar/chendong/2016/05/04/1462333056-57296e80bbfa2.doc
    [path] => /avatar/chendong/2016/05/04
    [name] => 1462333056-57296e80bbfa2.doc
)

$filename = '/test/a.jpg';
$content = $storage->read($filename);

$filename = '/test/a.jpg';
$result = $storage->delete($filename);