PHPackages                             deanar/yii2-file-processor - 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. deanar/yii2-file-processor

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

deanar/yii2-file-processor
==========================

Upload and process files and images for Yii2

0.1.3(10y ago)116035[1 issues](https://github.com/rdeanar/yii2-file-processor/issues)BSD-4-ClausePHPPHP &gt;=5.4.0

Since Mar 10Pushed 9y ago3 watchersCompare

[ Source](https://github.com/rdeanar/yii2-file-processor)[ Packagist](https://packagist.org/packages/deanar/yii2-file-processor)[ RSS](/packages/deanar-yii2-file-processor/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (4)Versions (7)Used By (0)

File Processor (Yii2 Extension)
===============================

[](#file-processor-yii2-extension)

Upload and process files and images.

Based on jquery.fileapi [Link to github](https://github.com/RubaXa/jquery.fileapi)

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist deanar/yii2-file-processor:"0.1.*"

```

or add

```
"deanar/yii2-file-processor": "0.1.*"

```

to the require section of your `composer.json` file and update composer dependencies;

If installation fails, try to use minimum stability: dev.

Then run migrations

```
 ./yii migrate/up --migrationPath=@deanar/fileProcessor/migrations
```

Include module into your web config

```
'modules' => [
    'fp' => [
        'class' => 'deanar\fileProcessor\Module',
        //'image_driver' => \deanar\fileProcessor\models\Uploads::IMAGE_DRIVER_GD,
        'variations_config' => require(__DIR__ . '/file_processor_variations.php'),
        //'root_path' => '@frontend/web', // default: @webroot
        //'root_url' => 'http://front.example.com', // default: current host (Yii::$app->request->getHostInfo())
        'upload_dir' => 'uploads',
        //'default_quality' => 95,
        //'default_resize_mod' => 'outbound',
        //'unlink_files' => true,
        //'debug' => true, // FileAPI debug. false by default
    ],
]
```

Attach behavior to your model

```
public function behaviors()
{
    return [
        'fileSequence' => [
            'class' => \deanar\fileProcessor\behaviours\ConnectFileSequence::className(),
            'defaultType' => 'projects',
            'registeredTypes' => ['projects', 'files'], // or 'projects, files' as string
        ]
    ];
}
```

Create file `file_processor_variations.php` in config directory and configure image variations like:

```
use deanar\fileProcessor\components\WatermarkFilter;

return [
    'projects' => [
        '_original' => false,
        'thumb' => [200, 150, 'inset'],
        'small' => [300, 200, 'outbound', 75],
        'big' => [
            'width' => 600,
            'height' => 350,
            'mode' => 'outbound',
            'quality' => 75,
            'watermark' => [
                'path' => 'watermark.png',
                'position' => WatermarkFilter::WM_POSITION_BOTTOM_RIGHT,
                'margin' => 10,
            ]
        ],
    ],
    'article_header' => [
        '_original' => true,
        'thumb' => [200, 150, 'inset'],
    ],
    'avatar_picture' => [
        '_original' => true,
        'preview' => [200, 200, 'outbound'],

        // For single file uploads. Automatically will be updated 'avatar' attribute in 'Project' model
        // with  of currently uploaded file
        '_insert' => ['app\models\Project' => 'avatar'],

        // variants of access control definitions
        '_acl'       => '*', // * - all users, like without _acl
        '_acl'       => '@', // @ - authenticated users only
        '_acl'       => ['users' => ['admin', 'user1']], // defined list of users
        '_acl'       => ['app\models\Project' => 'user_id'], // if current user id equals to `user_id` attribute of model `app\models\Project`
        '_acl'       => function ($type_id, $user_id) { // callable check
            return \app\models\Project::findOne($type_id)->user_id == $user_id;
        },

    ],

    // Used if no variation with specified name found
    '_default' => [ ],

    // Mixin for all variations. Used by merging arrays.
    '_all' => [ ],
];
```

**NB!** Don't forget to disable php execution in your upload dir. For example: If you use Apache web server, you can create `.htaccess` file in the root of upload directory with the following code inside:

```
RemoveHandler .php
AddType text/html .php

```

Upgrade instruction
-------------------

[](#upgrade-instruction)

Run migrations

```
 ./yii migrate/up --migrationPath=@deanar/fileProcessor/migrations
```

In ConnectFileSequence behaviour replace `deleteTypes` property to `registeredTypes`.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your form by adding widget code to view:

Multi upload widget:

```
