developit / yii2-flysystem-wrapper
yii2 flysystem wrapper
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 5
Type:yii2-extension
Requires
- creocoder/yii2-flysystem: 0.8.*
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2025-03-29 00:42:27 UTC
README
yii2 flysystem wrapper. Flysystem is a filesystem abstraction which allows you to easily swap out a local filesystem for a remote one.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist developit/yii2-flysystem-wrapper "*"
or add
"developit/yii2-flysystem-wrapper": "*"
to the require section of your composer.json
file.
then up migrations
php yii migrate/up --migrationPath=vendor/developit/yii2-flysystem-wrapper/migrations
Usage/Features
Once the extension is installed, simply use it in your code by :
add "fs" to components
'fs' => [ 'class' => 'Integral\Flysystem\Adapter\PDOAdapter', // or other adapters 'tableName' => 'file_storage' ],
upload sample code
<?php $model = new MyModel(); if (Yii::$app->request->isPost) { $model->files = UploadedFile::getInstancesByName('files'); if ($model->validate()) { $data = [ 'path' => '@common/files', 'context' => '025', 'version' => '1', 'metadata' => ['meta' => 1, 'meta2' => 2, 'meta3' => 3], ]; return FlysystemWrapper::upload($model->files, $data); } return $model; } ?>
note: in model file rule "maxFiles" is required
<?php [['files'], 'file', 'skipOnEmpty' => false, 'maxFiles' => 10, 'extensions' => 'txt, jpg'] ?>
get a file by hash key
<?php $hashKey = 'XXX'; return FlysystemWrapper::getByHash($hashKey); ?>
note: delete method is logical
search file(s) by metadatas or file model spesial attributes
<?php $params = ['meta1' => 1, 'version' => 2]; return FlysystemWrapper::searchByParams($params); ?>