An Oss client of yii2 extension.
Installation
The preferred way to install this extension is through composer., (*1)
Either run, (*2)
php composer.phar require --prefer-dist hxy2015/yii2-oss
or add, (*3)
"hxy2015/yii2-oss": "~1.0"
to the require section of your composer.json., (*4)
Configuration
To use this extension, you have to configure the Connection class in your application configuration:, (*5)
return [
//....
'components' => [
'oss' => [
'hostname' => 'localhost',
'bucket' => 'risk-test',
'accessId' => 'test', // oss id
'accessKey' => 'test', // oss id
],
]
];
Usage
Upload File, (*6)
$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);
Download File, (*7)
$oss = \Yii::$app->get('oss');
$oss->getObjectContent('some_dir/some_file_name');
$filename = 'test.txt';
$oss->getObjectFile('some_dir/some_file_name', $filename);
Test File Exist, (*8)
$oss = \Yii::$app->get('oss');
$oss->isObjectExist('some_dir/some_file_name');