PHPackages                             fabriziocaldarelli/yii2-file-upload - 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. fabriziocaldarelli/yii2-file-upload

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

fabriziocaldarelli/yii2-file-upload
===================================

File upload for Yii2

1.1.3(1y ago)2718↓66.7%MITPHP

Since Jun 16Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/fcaldarelli/yii2-file-upload)[ Packagist](https://packagist.org/packages/fabriziocaldarelli/yii2-file-upload)[ RSS](/packages/fabriziocaldarelli-yii2-file-upload/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (2)Versions (5)Used By (0)

File upload for Yii2
====================

[](#file-upload-for-yii2)

Single and Multiple file upload handler for Yii2

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist fabriziocaldarelli/yii2-file-upload "*"

```

or add

```
"fabriziocaldarelli/yii2-file-upload": "*"

```

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

Configuration
-------------

[](#configuration)

Once the extension is installed, configure it in config\\main.php setting imageBaseUrl, fileUploadBasePath and fileUploadBaseUrl :

**1) Add fileUploader module to config.php**

```
'modules' => [
    'fileUploader' => [
        'class' => 'sfmobile\fileUpload\Module',

        // Database table name to save files metadata
        'dbTableName' => 'tbl_file_upload',

        'defaultStorage' => 's3prod',

        'storages' => [
            's3prod' => [
                'class' => 'sfmobile\fileUpload\storages\S3Storage',

                's3Key' => 'PROD',
                's3Secret' => '1234567',
                's3Endpoint' => 'https://mys3',
                's3Bucket' => 'mybucket',
            ],
            'local' => [
                'class' => 'sfmobile\fileUpload\storages\FileSystemStorage',

                'basePath' =>  '/var/www/vhosts/your_hosting/public_files',
                'baseUrl' =>  '/public_files',
            ],
        ]
    ],
],
```

**2) Add the module in bootstrap section of config\\main.php**

```
'bootstrap' => ['log', 'fileUploader'],
```

**3) Apply database migration**

```
yii migrate --migrationPath=@vendor/fabriziocaldarelli/yii2-file-upload/migrations

```

Changes to Model, View and Controller
-------------------------------------

[](#changes-to-model-view-and-controller)

I suggest to create ModelForm class that extends Model class and add an attribute to handle files (in this case, 'photo')

If you need to update other fields on database, sync() method has a last parameter $options that has this structure:

`@param $options array of [ 'filter' => [  'andWhere' => [] ], 'saveFields' => [ 'array of fields' ] ]`

filter-&gt;andWhere data contains other field to match the record, saveFields contains set of key=&gt;value fields to insert/update.

**Changes to Model**

```
