<commit_before># FileManager for Yii2

[![Build Status](https://travis-ci.org/rkit/filemanager-yii2.svg?branch=master)](https://travis-ci.org/rkit/filemanager-yii2)
[![Code Coverage](https://scrutinizer-ci.com/g/rkit/filemanager-yii2/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/rkit/filemanager-yii2/?branch=master)
[![codecov.io](http://codecov.io/github/rkit/filemanager-yii2/coverage.svg?branch=master)](http://codecov.io/github/rkit/filemanager-yii2?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/rkit/filemanager-yii2/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/rkit/filemanager-yii2/?branch=master)

## Features

- Upload with validations
- Create thumbnails on the fly with cache or after upload
- Easy setup presets for files
- Ability to use any component for working with images
- Support for multiple file uploads
- Check the Owner of a file
- Storing information about a file in the database

## Installation

1. Installing using Composer
   ```
   composer require rkit/filemanager-yii2
   ```

2. Run migrations
   ```
   php yii migrate --migrationPath=@vendor/rkit/filemanager-yii2/src/migrations/ --interactive=0
   ```

## Configuration

Add the following in your config, in section `components`

```php
'fileManager' => [
    'class' => 'rkit\filemanager\FileManager',
    // directory for files inaccessible from the web
    'uploadDirProtected' => '@app/runtime',
    // directory for files available from the web
    'uploadDirUnprotected' => '@app/web',
    // path in a directory of upload
    'publicPath' => 'uploads',
    // an array of the types of owners, in the format of `table.attribute` => `unique value`
    'ownerTypes' => [
        'news.text' => 1,
        'news.preview' => 2,
        'news.gallery' => 3,
        'user_profile.photo' => 4,
    ]
]
```

## Usage

### Basic usage

1. **Controller**

   ```php
   public function behaviors()
   {
       return [
           'verbs' => [
               'class' => VerbFilter::className(),
               'actions' => [
                   'preview-upload' => ['post']
               ],
           ],
       ];
   }

   public function actions()
   {
       return [
           'preview-upload' => [
               'class'     => 'rkit\filemanager\actions\UploadAction',
               'modelName' => 'app\models\News',
               'attribute' => 'preview',
               'type'      => 'image', // `image` or `file` for non-images
               'inputName' => 'file' // the name of the file input field<commit_msg>Upd README.md<commit_after># FileManager for Yii2

[![Build Status](https://travis-ci.org/rkit/filemanager-yii2.svg?branch=master)](https://travis-ci.org/rkit/filemanager-yii2)
[![Code Coverage](https://scrutinizer-ci.com/g/rkit/filemanager-yii2/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/rkit/filemanager-yii2/?branch=master)
[![codecov.io](http://codecov.io/github/rkit/filemanager-yii2/coverage.svg?branch=master)](http://codecov.io/github/rkit/filemanager-yii2?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/rkit/filemanager-yii2/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/rkit/filemanager-yii2/?branch=master)

## Features

- Upload with validations
- Create thumbnails on the fly with cache or after upload
- Easy setup presets for files
- Ability to use any component for working with images
- Support for multiple file uploads
- Check the Owner of a file
- Storing information about a file in the database

## Installation

1. Installing using Composer
   ```
   composer require rkit/filemanager-yii2
   ```

2. Run migrations
   ```
   php yii migrate --migrationPath=@vendor/rkit/filemanager-yii2/src/migrations/ --interactive=0
   ```

## Configuration

Add the following in your config, in section `components`

```php
'fileManager' => [
    'class' => 'rkit\filemanager\FileManager',
    // directory for files inaccessible from the web
    'uploadDirProtected' => '@app/runtime',
    // directory for files available from the web
    'uploadDirUnprotected' => '@app/web',
    // path in a directory of upload
    'publicPath' => 'uploads',
    // an array of the types of owners, in the format of `table.attribute` => `unique value`
    'ownerTypes' => [
        'news.text' => 1,
        'news.preview' => 2,
        'news.gallery' => 3,
        'user_profile.photo' => 4,
    ]
]
```

## Usage

### Basic usage

> The example uses [Intervention\Image](https://github.com/Intervention/image), but this is optional.

1. **Controller**

   ```php
   public function behaviors()
   {
       return [
           'verbs' => [
               'class' => VerbFilter::className(),
               'actions' => [
                   'preview-upload' => ['post']
               ],
           ],
       ];
   }

   public function actions()
   {
       return [
           'preview-upload' => [
               'class'     => 'rkit\filemanager\actions\UploadAction',
               'modelName' => 'app\models\News',
               'attribute' => 'preview',
               'type'      => 'image', // `image` or `file` for non-images
               'inputName' => 'file' // the name of the file input field
{'fraction_non_alphanumeric': 0.1487492839411877, 'fraction_numerical': 0.007256062631277449, 'mean_word_length': 2.757532281205165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 46, 'https://': 13, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '35951', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1643, 'n_words': 370}