PHPackages                             sinus/yii2-filemanager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. sinus/yii2-filemanager

ActiveYii2-extension[File &amp; Storage](/categories/file-storage)

sinus/yii2-filemanager
======================

Yii2 filemanager

02

Since Feb 21Pushed 6y agoCompare

[ Source](https://github.com/sinus22/yii2-filemanager)[ Packagist](https://packagist.org/packages/sinus/yii2-filemanager)[ RSS](/packages/sinus-yii2-filemanager/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 file manager
=================

[](#yii2-file-manager)

This module provide interface to collect and access all mediafiles in one place. Inspired by WordPress file manager.

Features
--------

[](#features)

- Integrated with TinyMCE editor.
- Automatically create actually directory for uploaded files like "2014/12".
- Automatically create thumbs for uploaded images
- Unlimited number of sets of miniatures
- All media files are stored in a database that allows you to attach to your object does not link to the image, and the id of the media file. This provides greater flexibility since in the future will be easy to change the size of thumbnails.
- If your change thumbs sizes, your may resize all existing thumbs in settings.

Screenshots
-----------

[](#screenshots)

[![](https://camo.githubusercontent.com/ae5ae7ad69aca3e5fe23fde7c92293e55aa246b6aaddd68d18c6f1320c4a638d/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d75706c6f61642e706e67)](https://camo.githubusercontent.com/ae5ae7ad69aca3e5fe23fde7c92293e55aa246b6aaddd68d18c6f1320c4a638d/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d75706c6f61642e706e67)

[![](https://camo.githubusercontent.com/7a3b0e1cf164e4f8451f5cf96772650734f4addf7fbb1e794559897c7c707527/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d696d6167652d73656c6563742e706e67)](https://camo.githubusercontent.com/7a3b0e1cf164e4f8451f5cf96772650734f4addf7fbb1e794559897c7c707527/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d696d6167652d73656c6563742e706e67)

[![](https://camo.githubusercontent.com/f31389d9104e547cfd3efc721a49563aa9a0c86ab34dbb1b38880dbfa31d0363/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d696e6465782e706e67)](https://camo.githubusercontent.com/f31389d9104e547cfd3efc721a49563aa9a0c86ab34dbb1b38880dbfa31d0363/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d696e6465782e706e67)

[![](https://camo.githubusercontent.com/e86adbaa041419ca5086d2885880a4446b820dca34ce0439b7e852f944f9814e/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d66696c65732d696e2d61646d696e2e706e67)](https://camo.githubusercontent.com/e86adbaa041419ca5086d2885880a4446b820dca34ce0439b7e852f944f9814e/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d66696c65732d696e2d61646d696e2e706e67)

[![](https://camo.githubusercontent.com/0462a2852ad9000598235bf8d931f74110137c25b4a601078a44c5fe65147ea2/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d73657474696e67732e706e67)](https://camo.githubusercontent.com/0462a2852ad9000598235bf8d931f74110137c25b4a601078a44c5fe65147ea2/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d73657474696e67732e706e67)

[![](https://camo.githubusercontent.com/ef6d59e30bd568b043476e058426bf0e0c4578455b9f879f1d103eb6f8dbc951/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d73656c65637465642d696d6167652e706e67)](https://camo.githubusercontent.com/ef6d59e30bd568b043476e058426bf0e0c4578455b9f879f1d103eb6f8dbc951/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d73656c65637465642d696d6167652e706e67)

[![](https://camo.githubusercontent.com/7e3d3afee24dccf0d51e43c2b31ce7923e54987812bfa72e20616fb86ba961df/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d73656c65637465642d696d6167652d776974686f75742d696e7075742e706e67)](https://camo.githubusercontent.com/7e3d3afee24dccf0d51e43c2b31ce7923e54987812bfa72e20616fb86ba961df/687474703a2f2f7a61626f6c6f74736b696b682e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f31322f796969322d66696c656d616e616765722d73656c65637465642d696d6167652d776974686f75742d696e7075742e706e67)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist pendalf89/yii2-filemanager "*"

```

or add

```
"pendalf89/yii2-filemanager": "*"

```

to the require section of your `composer.json` file.

Apply migration

```
yii migrate --migrationPath=vendor/pendalf89/yii2-filemanager/migrations
```

Configuration:

```
'modules' => [
    'filemanager' => [
        'class' => 'pendalf89\filemanager\Module',
        // Upload routes
        'routes' => [
            // Base absolute path to web directory
            'baseUrl' => '',
            // Base web directory url
            'basePath' => '@frontend/web',
            // Path for uploaded files in web directory
            'uploadPath' => 'uploads',
        ],
        // Thumbnails info
        'thumbs' => [
            'small' => [
                'name' => 'Мелкий',
                'size' => [100, 100],
            ],
            'medium' => [
                'name' => 'Средний',
                'size' => [300, 200],
            ],
            'large' => [
                'name' => 'Большой',
                'size' => [500, 400],
            ],
        ],
    ],
],
```

By default, thumbnails are resized in "outbound" or "fill" mode. To switch to "inset" or "fit" mode, use `mode` parameter and provide. Possible values: `outbound` (`\Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND`) or `inset` (`\Imagine\Image\ImageInterface::THUMBNAIL_INSET`):

```
'thumbs' => [
    'small' => [
        'name' => 'Мелкий',
        'size' => [100, 100],
    ],
    'medium' => [
        'name' => 'Средний',
        'size' => [300, 200],
    ],
    'large' => [
        'name' => 'Большой',
        'size' => [500, 400],
        'mode' => \Imagine\Image\ImageInterface::THUMBNAIL_INSET
    ],
],
```

Usage
-----

[](#usage)

Simple standalone field:

```
use pendalf89\filemanager\widgets\FileInput;

echo $form->field($model, 'original_thumbnail')->widget(FileInput::className(), [
    'buttonTag' => 'button',
    'buttonName' => 'Browse',
    'buttonOptions' => ['class' => 'btn btn-default'],
    'options' => ['class' => 'form-control'],
    // Widget template
    'template' => '{input}{button}',
    // Optional, if set, only this image can be selected by user
    'thumb' => 'original',
    // Optional, if set, in container will be inserted selected image
    'imageContainer' => '.img',
    // Default to FileInput::DATA_URL. This data will be inserted in input field
    'pasteData' => FileInput::DATA_URL,
    // JavaScript function, which will be called before insert file data to input.
    // Argument data contains file data.
    // data example: [alt: "Ведьма с кошкой", description: "123", url: "/uploads/2014/12/vedma-100x100.jpeg", id: "45"]
    'callbackBeforeInsert' => 'function(e, data) {
        console.log( data );
    }',
]);

echo FileInput::widget([
    'name' => 'mediafile',
    'buttonTag' => 'button',
    'buttonName' => 'Browse',
    'buttonOptions' => ['class' => 'btn btn-default'],
    'options' => ['class' => 'form-control'],
    // Widget template
    'template' => '{input}{button}',
    // Optional, if set, only this image can be selected by user
    'thumb' => 'original',
    // Optional, if set, in container will be inserted selected image
    'imageContainer' => '.img',
    // Default to FileInput::DATA_IDL. This data will be inserted in input field
    'pasteData' => FileInput::DATA_ID,
    // JavaScript function, which will be called before insert file data to input.
    // Argument data contains file data.
    // data example: [alt: "Ведьма с кошкой", description: "123", url: "/uploads/2014/12/vedma-100x100.jpeg", id: "45"]
    'callbackBeforeInsert' => 'function(e, data) {
        console.log( data );
    }',
]);
```

With TinyMCE:

```
use pendalf89\filemanager\widgets\TinyMCE;
