airani / yii2-flysystem
Yii2 Flysystem 组件
v1.0
2017-08-18 21:48 UTC
Requires
- league/flysystem: ~1.0
- yiisoft/yii2: ~2.0
This package is auto-updated.
Last update: 2024-09-08 23:11:34 UTC
README
Flysystem 组件是为 Yii2 PHP 框架设计的,比类似组件具有更多灵活性,并与 Flysystem MountManager 集成,以返回作为 Yii2 组件的 Flysystem 对象,有助于与其他与 Flysystem 集成的库(如 Glide)一起工作。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令:
composer require airani/yii2-flysystem
或者
"airani/yii2-flysystem": "~1.0"
将其添加到您的 composer.json 文件的 require 部分中。
配置
根据以下步骤配置任何文件系统适配器的应用程序组件:
return [ // ... 'componenets' => [ // ... 'flysystem' => [ 'class' => 'airani\flysystem\MountManager', 'localFs' => [ // https://flysystem.thephpleague.com/adapter/local/ 'class' => 'League\Flysystem\Adapter\Local', 'root' => __DIR__.'/path/to/too', ], 'ftpFs' => [ // https://flysystem.thephpleague.com/adapter/ftp/ 'class' => 'League\Flysystem\Adapter\Ftp', 'config' => [ 'host' => 'ftp.example.com', 'username' => 'username', 'password' => 'password', // optional config settings 'port' => 21, 'root' => '/path/to/root', 'passive' => true, 'ssl' => true, 'timeout' => 30, ], ], // and config other filesystem adapters // read adapters section of flysystem guide https://flysystem.thephpleague.com ], ], ];
用法
要使用 MountManager
// Read from FTP $contents = Yii::$app->flysystem->read('ftp://some/file.txt'); // And write to local Yii::$app->flysystem->write('local://put/it/here.txt', $contents);
或者简单使用
Yii::$app->filesystem->localFs->write('path/to/file.txt', 'contents');
有关如何使用 flysystem 的信息,请参阅此 API 文档。