PHPackages                             sweelix/yii2-plupload - 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. sweelix/yii2-plupload

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

sweelix/yii2-plupload
=====================

PHP 5.4+ Sweelix Yii2 plupload extension - easy asynchronous file uploads

1.0.3(12y ago)1930.1k↓36.4%8[4 issues](https://github.com/pgaultier/sweelix-yii2-plupload/issues)BSD-3-ClausePHP

Since Apr 2Pushed 10y ago3 watchersCompare

[ Source](https://github.com/pgaultier/sweelix-yii2-plupload)[ Packagist](https://packagist.org/packages/sweelix/yii2-plupload)[ RSS](/packages/sweelix-yii2-plupload/feed)WikiDiscussions devel Synced 2d ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

Sweelix Yii2 Plupload extension
===============================

[](#sweelix-yii2-plupload-extension)

Sweelix Plupload extension for Yii 2 has been created to ease Plupload integration.

Plupload is not affiliated with Sweelix

Be carefull, Plupload () is multi-licensed. Take care of the license which applies to :

- GPLv2 :
- Commercial :

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

[](#installation)

If you use Packagist for installing packages, then you can update your composer.json like this :

```
{
    "require": {
        "sweelix/yii2-plupload": "*"
    }
}
```

Howto use this extension
------------------------

[](#howto-use-this-extension)

Once package has been installed:

activate Image management,by adding it to Yii components

```
// Yii2 app configuration
components => [

    // ... exiting components

    'image' => [
        'class' => 'sweelix\yii2\image\Config',
        'quality' => 80,
        'cachingMode' => sweelix\image\Image::MODE_NORMAL,
        'urlSeparator' => '/',
        'cachePath' => '@webroot/cache',
        'cacheUrl' => '@web/cache',
        'errorImage' => 'error.jpg',
    ]

    // ... exiting components

]
```

add the extension in your `Html` helper class :

```
namespace app\components;

use yii\helpers\Html as BaseHtml;
use sweelix\yii2\plupload\traits\Plupload;

class Html extends BaseHtml
{
    // adding this trait allow easy access to plupload
    use Plupload;
}
```

### Basic usage

[](#basic-usage)

**Sample one** : one single file upload with basic UI and Automatic upload

The controller file

```
namespace app\controllers;

use sweelix\yii2\plupload\components\UploadedFile;
use yii\web\Controller;
use Yii;

/**
 * This is a basic controller
 */
class SiteController extends Controller {
    public function actions() {
        // add upload / preview and delete file management
        return [
            'async-upload' => 'sweelix\yii2\plupload\actions\UploadFile',
            'async-delete' => 'sweelix\yii2\plupload\actions\DeleteFile',
            'async-preview' => 'sweelix\yii2\plupload\actions\PreviewFile',
        ];
    }

    public function actionIndex() {
        if(isset($_POST['demoUpload']) === true) {
            $uploads = UploadedFile::getInstancesByName('demoUpload');
            // retrieve all uploaded files for name demoUpload
            foreach($uploads as $uploadedFile) {
                $uploadedFile->saveAs('@webroot/resources/'.$uploadedFile->name);
            }
            // ... perform correct redirection
        }

        $this->render('index');
    }
}
```

The index view file

```
// ...

echo Html::asyncInput('demoUpload', isset($_POST['demoUpload'])?$_POST['demoUpload']:null, ['config' => [
        'ui' => true,
        'auto' => true,
    ]]); ?>

//...
```

**Sample two** : multi-file upload with basic UI and Automatic upload

The controller file (*nothing was changed in the controller*)

```
namespace app\controllers;

use sweelix\yii2\plupload\components\UploadedFile;
use yii\web\Controller;
use Yii;

/**
 * This is a basic controller
 */
class SiteController extends Controller {
    public function actions() {
        // add upload / preview and delete file management
        return [
            'async-upload' => 'sweelix\yii2\plupload\actions\UploadFile',
            'async-delete' => 'sweelix\yii2\plupload\actions\DeleteFile',
            'async-preview' => 'sweelix\yii2\plupload\actions\PreviewFile',
        ];
    }

    public function actionIndex() {
        if(isset($_POST['demoUpload']) === true) {
            $uploads = UploadedFile::getInstancesByName('demoUpload');
            // retrieve all uploaded files for name demoUpload
            foreach($uploads as $uploadedFile) {
                $uploadedFile->saveAs('@webroot/resources/'.$uploadedFile->name);
            }
            // ... perform correct redirection
        }

        $this->render('index');
    }
}
```

The index view file, the square brackets here tell plupload to use multifile upload

```
// ...

echo Html::asyncInput('demoUpload[]', isset($_POST['demoUpload'])?$_POST['demoUpload']:null, ['config' => [
        'ui' => true,
        'auto' => true,
    ]]); ?>

//...
```

**Config parameter** this parameter allow the developper to configure [plupload](http://www.plupload.com/docs/Options)

Here are the default configuration

PHP namePlupload nameDefault valueruntimesruntimeshtml5, html4multiSelectionmulti\_selectionfalsemaxFileSizemax\_file\_size0chunkSizechunk\_size10MbuniqueNamesunique\_namesfalseflashSwfUrlflash\_swf\_urlnullsilverlightXapUrlsilverlight\_xap\_urlnullbrowseButtonbrowse\_buttonnulldropElementdrop\_elementnullcontainercontainernullmultipartmultipartnullmultipartParamsmultipart\_paramsnullrequiredFeaturesrequired\_featuresnullfiltersfiltersnullheadersheadersnull### Model usage with manual file management

[](#model-usage-with-manual-file-management)

The model file

```
namespace app\models;
use yii\db\ActiveRecord;
use Yii;

/**
 * Basic active record with uploadId (pkey autoincrement) and uploadFile (text)
 */
class Upload extends ActiveRecord {
    public static function tableName() {
        return '{{uploads}}';
    }
    public function rules() {

        return [
            // this rule is used to configure plupload :
            //   * maxFiles   trigger multifile upload,
            //   * extensions trigger the plupload filters
            //   * maxSize    trigger the maxFileSize
            ['uploadFile', 'file', 'extensions' => ['jpg', 'png', 'm4a'], 'maxFiles' => 1, 'maxSize' => 450*1024],
        ];
    }
    public function attributeLabels() {
        return [
            'uploadId' => Yii::t('sweelix', 'Upload ID'),
            'uploadFile' => Yii::t('sweelix', 'Uploaded File'),
        ];
    }
}
```

The controller file

```
namespace app\controllers;

use app\models\Upload;
use sweelix\yii2\plupload\components\UploadedFile;
use yii\web\Controller;
use Yii;

/**
 * This is a basic controller
 */
class SiteController extends Controller
{
    public function actions() {
        // add upload / preview and delete file management
        return [
            'async-upload' => 'sweelix\yii2\plupload\actions\UploadFile',
            'async-delete' => 'sweelix\yii2\plupload\actions\DeleteFile',
            'async-preview' => 'sweelix\yii2\plupload\actions\PreviewFile',
        ];
    }

    public function actionIndex() {
        $fileUpload = new Upload();
        if($fileUpload->load($_POST) === true) {
            // ... perform pre save
            $uploads = UploadedFile::getInstances($fileUpload, 'uploadFile');
            // retrieve all uploaded files for name demoUpload
            foreach($uploads as $uploadedFile) {
                // ... save file ...
                $uploadedFile->saveAs('@webroot/resources/'.$uploadedFile->name);
            }

            // ... perform post file save
            $fileUpload->save();
            // ... perform correct redirection
        }

        $this->render('index', ['fileUpload' => $fileUpload]);
    }
}
```

The index view file

```
// ...

//...
```

### Model usage with automatic file management

[](#model-usage-with-automatic-file-management)

The model file

```
namespace app\models;
use sweelix\yii2\plupload\behaviors\AutomaticUpload;
use yii\db\ActiveRecord;
use Yii;

/**
 * Basic active record with uploadId (pkey autoincrement) and uploadFile (text)
 */
class Upload extends ActiveRecord
{
    public static function tableName() {
        return '{{uploads}}';
    }

    public function behaviors() {
        return [
            [
                'class' => AutomaticUpload::className(),
                'attributes' => [
                    'uploadFile' => [
                        // define where to save the file
                        'basePath' => '@webroot/resources',
                        // define the url to access the file
                        'baseUrl' => '@web/resources',
                    ],
                ]
            ]
        ];
    }

    public function rules() {
        return [
            // this rule is used to configure plupload :
            //   * maxFiles   trigger multifile upload,
            //   * extensions trigger the plupload filters
            //   * maxSize    trigger the maxFileSize
            ['uploadFile', 'file', 'extensions' => ['jpg', 'png', 'm4a'], 'maxFiles' => 1, 'maxSize' => 450*1024],
        ];
    }
    public function attributeLabels() {
        return [
            'uploadId' => Yii::t('sweelix', 'Upload ID'),
            'uploadFile' => Yii::t('sweelix', 'Uploaded File'),
        ];
    }
}
```

The controller file

```
namespace app\controllers;

use app\models\Upload;
use sweelix\yii2\plupload\components\UploadedFile;
use yii\web\Controller;
use Yii;

/**
 * This is a basic controller
 */
class SiteController extends Controller
{
    public function actions() {
        // add upload / preview and delete file management
        return [
            'async-upload' => 'sweelix\yii2\plupload\actions\UploadFile',
            'async-delete' => 'sweelix\yii2\plupload\actions\DeleteFile',
            'async-preview' => 'sweelix\yii2\plupload\actions\PreviewFile',
        ];
    }

    public function actionIndex() {
        $fileUpload = new Upload();
        if($fileUpload->load($_POST) === true) {
            // ... file save is performed automagically
            $fileUpload->save();
            // ... perform correct redirection
        }

        $this->render('index', ['fileUpload' => $fileUpload]);
    }
}
```

The index view file

```
// ...

//...
```

Contributing
------------

[](#contributing)

All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.

Fork the project, create a [feature branch ](http://nvie.com/posts/a-successful-git-branching-model/), and send us a pull request.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 98.3% of commits — single point of failure

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 ~16 days

Total

4

Last Release

4425d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/545714?v=4)[pgaultier](/maintainers/pgaultier)[@pgaultier](https://github.com/pgaultier)

---

Top Contributors

[![pgaultier](https://avatars.githubusercontent.com/u/545714?v=4)](https://github.com/pgaultier "pgaultier (59 commits)")[![dghyse](https://avatars.githubusercontent.com/u/8821954?v=4)](https://github.com/dghyse "dghyse (1 commits)")

---

Tags

asynchronousfilebehaviorsyiiplupload

### Embed Badge

![Health badge](/badges/sweelix-yii2-plupload/health.svg)

```
[![Health](https://phpackages.com/badges/sweelix-yii2-plupload/health.svg)](https://phpackages.com/packages/sweelix-yii2-plupload)
```

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k679.9M2.5k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.7k285.7M1.0k](/packages/league-flysystem-aws-s3-v3)[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k41.5M133](/packages/knplabs-gaufrette)[knplabs/knp-gaufrette-bundle

Allows to easily use the Gaufrette library in a Symfony project

72430.0M104](/packages/knplabs-knp-gaufrette-bundle)[league/flysystem-local

Local filesystem adapter for Flysystem.

225267.1M89](/packages/league-flysystem-local)[league/flysystem-memory

In-memory filesystem adapter for Flysystem.

8737.3M276](/packages/league-flysystem-memory)

PHPackages © 2026

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