tmukherjee13/yii2-storage

File system Abstraction Layer for Yii2

Installs: 13

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

dev-master 2016-12-12 07:30 UTC

This package is auto-updated.

Last update: 2024-10-29 04:47:26 UTC


README

File system Abstraction Layer for Yii2

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist tmukherjee13/yii2-storage "*"

or add

"tmukherjee13/yii2-storage": "*"

to the require section of your composer.json file.

Usage

Create a file '_storage.php' inside the config directory of your application with the following contents:

<?php
    return [
        'components' => [
           'storage' => [
                'class'  => 'tmukherjee13\storage\S3Storage',
                'bucket' => '<your-s3-bucket-name>',
                'key'    => '<s3-access-key>',
                'secret' => '<s3-secret-key>',
                'region' => '<s3-bucket-region>',
            ]
        ]
    ];

To use your local filesystem as storage use:

<?php
    return [
        'components' => [
            'storage' => [
                'class'  => 'tmukherjee13\storage\LocalStorage',
                'path'   => 'uploads', //base directory for storage
                'create' => true,
            ]
        ]
    ];

To write data:

$storage = Yii::$app->storage;
$storage->write('dir/file.txt', 'Hello World!',true); // params are: file, content , overwrite

To read data:

$file = $storage->get('dir/file.txt');
echo $file->getContent();