PHP code example of callmez / yii2-file-system
1. Go to this page and download the library: Download callmez/yii2-file-system 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/ */
callmez / yii2-file-system example snippets
" ...
"callmez/yii2-file-system": "*"
},
'components' => [
'fileSystem' => [
'class' => 'callmez\file\system\Collection',
'fileSystems' => [
//根据需求可设置多个存储, 以下来使用例子
'local' => function() {
return new \callmez\file\system\FileSystem(
new \callmez\file\system\adapters\Local(\Yii::getAlias('@webroot\images'))
);
},
'qiniu' => function() {
return new \callmez\file\system\FileSystem(
new \callmez\file\system\adapters\Qiniu(
'七牛空间的 bucket',
'七牛空间的 access key',
'七牛空间的 access secret',
'七牛的空间域名,默认为 {bucket}.qiniu.com 选填'
)
);
}
]
]
]
// 集合方式
$local = Yii::$app->fileSystem->get('local');
$local->write('test.txt', 'hello world');
echo $local->read('test.txt');
$qiniu = Yii::$app->fileSystem->get('qiniu');
$qiniu->write('test.txt', 'hello world');
echo $qiniu->read('test.txt');
// wrapper 方式 (推荐)
//等同于Yii::$app->fileSystem->get('local')->write('test.txt', 'hello world');
Yii::$app->fileSystem->write('local://test.txt', 'hello world');
//等同于Yii::$app->fileSystem->get('qiniu')->write('test.txt', 'hello world');
Yii::$app->fileSystem->write('qiniu://test.txt', 'hello world');