rmrevin/yii2-file

Yii2 module for file management

Installs: 285

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 5

Forks: 5

Open Issues: 1

Type:yii2-extension

1.2.5 2017-11-22 11:41 UTC

This package is not auto-updated.

Last update: 2024-10-26 17:02:53 UTC


README

License Latest Stable Version Latest Unstable Version Total Downloads

Code Status

Scrutinizer Code Quality Code Coverage Travis CI Build Status Dependency Status

Installation

Add in composer.json:

{
    "require": {
        "rmrevin/yii2-file": "~1.1"
    }
}

Usage

In config

<?
// ...

return [
    // ...
    'modules' => [
        // ...
        'file' => [
            'class' => '\rmrevin\yii\module\File\Module',
            'upload_alias' => '@app/web/upload',
            'upload_web_alias' => '/upload',
            'storage_alias' => '@app/web/storage',
            'storage_web_alias' => '/storage',
            'max_upload_file_size' => 10, // megabytes
        ],
    ],
];

Save file into database

use rmrevin\yii\module\File;

// external resource
$File = File\models\File::push(new File\component\ExternalResource('https://www.google.ru/images/srpr/logo11w.png'));

// internal resource
$File = File\models\File::push(new File\component\InternalResource('/var/www/images/pick.png'));

// uploaded resource
$File = File\models\File::push(new File\component\UploadedResource(UploadedFile::getInstance($model, 'file')));

Manipulation with images

use rmrevin\yii\module\File;

$File = File\models\File::find()->one();
echo Html::img((string)$File->image()
    ->resizeByWidth(100));
// available methods: resize, resizeByWidth, resizeByHeight, crop, thumbnail, watermark, text