yii2-flysystem-wrapper Flysystem is a filesystem abstraction which allows you to easily swap out a local filesystem for a remote one.

  1. Requirements
  2. Installation
  3. Usage/Features
  4. Resources

...overview of the extension...

Requirements

yiisoft/yii2: integral/flysystem-pdo-adapter: 1.0. creocoder/yii2-flysystem: 0.8.*

Installation

The preferred way to install this extension is through composer. Either run

php composer.phar require --prefer-dist whc/yii2-flysystem-wrapper "dev-master"

or add

"whc/yii2-flysystem-wrapper": "dev-master"

to the require section of your composer.json file. then up migrations

php yii migrate/up --migrationPath=vendor/whc/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

[['files'], 'file', 'skipOnEmpty' => false, 'maxFiles' => 10, 'extensions' => 'txt, jpg']

get a file by hash key

$hashKey = 'XXX';
return FlysystemWrapper::getByHash($hashKey);

read a file by hash key

$hashKey = 'XXX';
return FlysystemWrapper::readByHash($hashKey);

delete a file by hash key

$hashKey = 'XXX';
return FlysystemWrapper::deleteByHash($hashKey);

search file(s) by metadatas

$metadata = ['meta1' => 1, $meta2 => 2];
return FlysystemWrapper::searchByMetadata($metadata);

Resources

0 0
1 follower
0 downloads
Yii Version: 2.0
License: GPL-3.0
Category: File System
Developed by: mr.rezaee
Created on: Oct 29, 2017
Last updated: 6 years ago

Related Extensions