PHPackages                             jakharbek/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. jakharbek/yii2-filemanager

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

jakharbek/yii2-filemanager
==========================

File Manager

3.0.1(7y ago)52782MITPHPCI failing

Since Jul 6Pushed 6y agoCompare

[ Source](https://github.com/jakharbek/yii2-filemanager)[ Packagist](https://packagist.org/packages/jakharbek/yii2-filemanager)[ RSS](/packages/jakharbek-yii2-filemanager/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (8)Versions (8)Used By (0)

File Manager
============

[](#file-manager)

File Manager

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

[](#installation)

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

Either run

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

```

or add

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

```

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

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by :

Migrations
----------

[](#migrations)

You need to do the migration

```
yii migrate --migrationPath=@vendor/jakharbek/yii2-filemanager/src/migrations

```

Module
------

[](#module)

You need to connect the module of the backend part app.`\jakharbek\filemanager\backend\Module`

```
'modules' => [
    'files' => \jakharbek\filemanager\backend\Module::class
],
```

Params
------

[](#params)

You need to add parameters to the application in the file. example

```
[
    'thumbs' => [
        'icon' => [
            'w' => 50,
            'h' => 50,
            'q' => 50,
            'slug' => 'icon'
        ],
        'small' => [
            'w' => 320,
            'h' => 320,
            'q' => 50,
            'slug' => 'small'
        ],
        'low' => [
            'w' => 640,
            'h' => 640,
            'q' => 50,
            'slug' => 'low'
        ],
        'normal' => [
            'w' => 1024,
            'h' => 1024,
            'q' => 50,
            'slug' => 'normal'
        ]
    ],
    'images_ext' => [
        'jpg',
        'png',
        'bmp',
        'gif'
    ],
    'use_file_name' => true,
    'use_queue' => false,
    'file_not_founded' => '14',
    //'file_not_founded' => 'http://img.domain.loc/files/1.jpg'
```

`thumbs` - thumbnails images
`images_ext` - images ext
`use_file_name` - When uploading a file, whether to use the file name in the file download or create a hash
`use_queue` - When uploading a file, is it necessary to use a queue to load some photos in the background mode?

Apply DI (dependency injection)
-------------------------------

[](#apply-di-dependency-injection)

There is a class `\jakharbek\filemanager\bootstrap\SetUp` you need to apply it to the initial download of the application as an example.

```
'bootstrap' => [
    \jakharbek\filemanager\bootstrap\SetUp::class
],
```

Ways to use
-----------

[](#ways-to-use)

There are two ways to use you can use using a relation in a database or a column in a table:

Method use via the relation
---------------------------

[](#method-use-via-the-relation)

Suppose you have a junction table for example

```
post_image
------------------
post_id
file_id
sort
-----------------

```

And let's say you have the appropriate relational methods in Active Record

```
public function getPostImages()
{
   return $this->hasMany(PostImage::className(), ['post_id' => 'post_id']);
}

public function getImages()
{
   return $this->hasMany(Files::className(), ['file_id' => 'file_id'])->viaTable('postImages', ['post_id' => 'post_id']);
}
```

And now you need to apply special behavior `jakharbek\filemanager\behaviors\FileRelationBehavior` for such cases.

For example:

```
'file_relation_image' => [
 'class' => FileRelationBehavior::class,
 'delimtr' => ',',
 'attribute' => 'file_image'
],
```

You will need to create a property for exchanging data between the form and the model in case it found `file_image`

```
public $file_image
```

or

```
private $_file_image;

public function getFileImage(){
   return $this->$_file_image;
}

public function setFileImage($value){
   return $this->$_file_image = $value;
}
```

Next, you need to add this property `file_image` to the rules of the model as `safe`. For example:

```
public function rules()
{
   return [
           [['file_image'], 'safe']],
    ];
}
```

Now you can apply a file load/upload widget `jakharbek\filemanager\widgets\FileInput` for this field.

For example

```
