PHPackages                             liv/yii2-file-kit - 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. liv/yii2-file-kit

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

liv/yii2-file-kit
=================

Yii2 file upload and storage kit plus, add JCrop and resize

1.2.0(10y ago)311BSD-3-ClausePHP

Since Sep 4Pushed 10y ago1 watchersCompare

[ Source](https://github.com/Liv1020/yii2-file-kit)[ Packagist](https://packagist.org/packages/liv/yii2-file-kit)[ RSS](/packages/liv-yii2-file-kit/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (11)Versions (11)Used By (0)

![Packagist](https://camo.githubusercontent.com/9569ce104966ff31cefa1919c4366e10e8a7a3fdde02146234d25df139b24c7f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74726e74762f796969322d66696c652d6b69742e737667)[![Dependency Status](https://camo.githubusercontent.com/b5b299fb99ba65d51919e976d2671fdf22b967ac4e97c20009afcf914ec5fa76/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f74726e74763a796969322d66696c652d6b69742f62616467652e737667)](https://www.versioneye.com/php/trntv:yii2-file-kit/2.0.0)

This kit is designed to automate routine processes of uploading files, their saving and storage. It includes:

- File upload widget (based on [Blueimp File Upload](https://github.com/blueimp/jQuery-File-Upload))
- Component for storing files (built on top of [flysystem](https://github.com/thephpleague/flysystem))
- Actions to download, delete, and view (download) files
- Behavior for saving files in the model and delete files when you delete a model

Demo
----

[](#demo)

Since file kit is a part of [yii2-starter-kit](https://github.com/trntv/yii2-starter-kit) it's demo can be found in starter kit demo [here](http://backend.yii2-starter-kit.terentev.net/article/create).

File Storage
============

[](#file-storage)

To work with the File Kit you need to configure FileStorage first. This component is a layer of abstraction over the filesystem

- Its main task to take on the generation of a unique name for each file and trigger corresponding events.

```
'fileStorage'=>[
    'class' => 'trntv\filekit\Storage',
    'baseUrl' => '@web/uploads'
    'filesystem'=> ...
        // OR
    'filesystemComponent' => ...
],
```

There are several ways to configure `Storage` to work with `flysystem`.

1. Create a builder class that implements `trntv\filekit\filesystem\FilesystemBuilderInterface` and implement method` build`which returns filesystem object Example:

```
namespace app\components;

use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as Adapter;
use trntv\filekit\filesystem\FilesystemBuilderInterface;

class LocalFlysystemBuilder implements FilesystemBuilderInterface
{
    public $path;

    public function build()
    {
        $adapter = new Local(\Yii::getAlias($this->path));
        return new Filesystem($adapter);
    }
}
```

Configuration:

```
'fileStorage'=>[
    ...
    'filesystem'=> [
        'class' => 'app\components\FilesystemBuilder',
        'path' => '@webroot/uploads'
        ...
    ]
]
```

Read more about flysystem at

Then you can use it like this:

```
$file = UploadedFile::getInstanceByName('file');
Yii::$app->fileStorage->save($file); // method will return new path inside filesystem
$files = UploadedFile::getInstancesByName('files');
Yii::$app->fileStorage->saveAll($files);
```

2. Use third-party extensions, `creocoder/yii2-flysystem` for example, and provide a name of the filesystem component in `filesystemComponent`Configuration:

```
'fs' => [
    'class' => 'creocoder\flysystem\LocalFilesystem',
    'path' => '@webroot/files'
    ...
],
'fileStorage'=>[
    ...
    'filesystemComponent'=> 'fs'
],
```

Actions
=======

[](#actions)

File Kit contains several Actions to work with uploads.

### Upload Action

[](#upload-action)

Designed to save the file uploaded by the widget

```
public function actions(){
    return [
           'upload'=>[
               'class'=>'trntv\filekit\actions\UploadAction',
               'validationRules' => [
                    ...
               ],
               'on afterSave' => function($event) {
                    /* @var $file \League\Flysystem\File */
                    $file = $event->file
                    // do something (resize, add watermark etc)
               }
           ]
       ];
}
```

See additional settings in the corresponding class

### Delete Action

[](#delete-action)

```
public function actions(){
    return [
       'delete'=>[
           'class'=>'trntv\filekit\actions\DeleteAction',
       ]
    ];
}
```

See additional settings in the corresponding class

### View (Download) Action

[](#view-download-action)

```
public function actions(){
    return [
       'view'=>[
           'class'=>'trntv\filekit\actions\ViewAction',
       ]
    ];
}
```

See additional settings in the corresponding class

Upload Widget
=============

[](#upload-widget)

Standalone usage

```
echo \trntv\filekit\widget\Upload::widget([
    'model'=>$model,
    'attribute'=>'files',
    'url'=>['upload'],
    'sortable'=>true,
    'maxFileSize'=>10 * 1024 * 1024,
    'maxNumberOfFiles'=>3 // default 1
]);
```

With ActiveForm

```
echo $form->field($model, 'files')->widget(
    '\trntv\filekit\widget\Upload',
    [
        'url'=>['upload'],
        'sortable'=>true,
        'maxFileSize'=>10 * 1024 * 1024, // 10 MiB
        'maxNumberOfFiles'=>3 // default 1
    ]
);
```

UploadBehavior
==============

[](#uploadbehavior)

This behavior is designed to save uploaded files in the corresponding relation.

Somewhere in model:

For multiple files

```
 public function behaviors()
 {
    return [
        'file' => [
            'class' => 'trntv\filekit\behaviors\UploadBehavior',
            'multiple' => true,
            'attribute' => 'files',
            'filesRelation' => 'uploadedFiles',
            'pathAttribute' => 'path',
            'baseUrlAttribute' => 'base_url',
            'typeAttribute' => 'type',
            'sizeAttribute' => 'size',
            'nameAttribute' => 'name',
            'orderAttribute' => 'order'
        ],
    ];
 }
```

For single file upload

```
 public function behaviors()
 {
     return [
          'file' => [
              'class' => 'trntv\filekit\behaviors\UploadBehavior',
              'attribute' => 'file',
              'pathAttribute' => 'path',
              'baseUrlAttribute' => 'base_url',
               ...
          ],
      ];
 }
```

See additional settings in the corresponding class.

Validation
==========

[](#validation)

There are two ways you can perform validation over uploads. On the client side validation is performed by Blueimp File Upload. Here is [documentation](https://github.com/blueimp/jQuery-File-Upload/wiki/Options#validation-options) about available options.

On the server side validation is performed by \[\[yii\\web\\UploadAction\]\], where you can configure validation rules for \[\[yii\\base\\DynamicModel\]\] that will be used in validation process

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~22 days

Total

11

Last Release

3946d ago

Major Versions

0.4 → 1.0.02015-03-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/eca8d58fc93deff22b5152606099bdcef7a0d3da0bf3a8a8d585c58dfede9bde?d=identicon)[Pavle Lee](/maintainers/Pavle%20Lee)

---

Top Contributors

[![trntv](https://avatars.githubusercontent.com/u/1162056?v=4)](https://github.com/trntv "trntv (2 commits)")[![1allen](https://avatars.githubusercontent.com/u/597599?v=4)](https://github.com/1allen "1allen (1 commits)")[![kharalampidi](https://avatars.githubusercontent.com/u/11192488?v=4)](https://github.com/kharalampidi "kharalampidi (1 commits)")[![xBazilio](https://avatars.githubusercontent.com/u/4119114?v=4)](https://github.com/xBazilio "xBazilio (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/liv-yii2-file-kit/health.svg)

```
[![Health](https://phpackages.com/badges/liv-yii2-file-kit/health.svg)](https://phpackages.com/packages/liv-yii2-file-kit)
```

###  Alternatives

[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M790](/packages/league-flysystem-aws-s3-v3)[yii2-starter-kit/yii2-file-kit

Yii2 file upload and storage kit

151216.8k6](/packages/yii2-starter-kit-yii2-file-kit)[league/flysystem-sftp-v3

SFTP filesystem adapter for Flysystem.

6129.6M91](/packages/league-flysystem-sftp-v3)[mihaildev/yii2-elfinder

Yii2 ElFinder

169658.8k52](/packages/mihaildev-yii2-elfinder)[limion/yii2-jquery-fileupload-widget

Blueimp file upload widget for Yii2

1224.5k](/packages/limion-yii2-jquery-fileupload-widget)[devgroup/yii2-dropzone

Yii2 Dropzone widget

1051.6k1](/packages/devgroup-yii2-dropzone)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
