PHP code example of hxy2015 / yii2-oss

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

    

hxy2015 / yii2-oss example snippets


return [
    //....
    'components' => [
        'oss' => [
            'hostname' => 'localhost',
            'bucket' => 'risk-test',
            'accessId' => 'test', // oss id
            'accessKey' => 'test', // oss id
        ],
    ]
];

$oss = \Yii::$app->get('oss');
$oss->putObjectByContent('some_dir/some_file_name', 'hehe');

$filename = 'test.txt';
file_put_contents($filename, 'hehe');
$oss->putObjectByFile('some_dir/some_file_name', $filename);

$oss = \Yii::$app->get('oss');
$oss->getObjectContent('some_dir/some_file_name');

$filename = 'test.txt';
$oss->getObjectFile('some_dir/some_file_name', $filename);

$oss = \Yii::$app->get('oss');
$oss->isObjectExist('some_dir/some_file_name');