PHPackages                             xj/yii2-uploadify-widget - 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. xj/yii2-uploadify-widget

ActiveLibrary

xj/yii2-uploadify-widget
========================

yii2-uploadify-widget

2.0.3(10y ago)1946.4k↓44.4%12BSD-3-ClauseJavaScript

Since Jan 27Pushed 8y ago8 watchersCompare

[ Source](https://github.com/xjflyttp/yii2-uploadify-widget)[ Packagist](https://packagist.org/packages/xj/yii2-uploadify-widget)[ RSS](/packages/xj-yii2-uploadify-widget/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (0)

yii2-uploadify-widget
=====================

[](#yii2-uploadify-widget)

===

composer.json
-------------

[](#composerjson)

---

```
"require": {
    "xj/yii2-uploadify-widget": "~2.0.0"
},

"require": {
    "xj/yii2-uploadify-widget": "~1.0.0"
},
```

example:
--------

[](#example)

### version 2.0

[](#version-20)

---

```
//Remove Events Auto Convert

use yii\web\JsExpression;

//外部TAG
echo Html::fileInput('test', NULL, ['id' => 'test']);
echo Uploadify::widget([
    'url' => yii\helpers\Url::to(['s-upload']),
    'id' => 'test',
    'csrf' => true,
    'renderTag' => false,
    'jsOptions' => [
        'width' => 120,
        'height' => 40,
        'onUploadError' => new JsExpression( new JsExpression( 'test']);
echo Uploadify::widget([
    'url' => yii\helpers\Url::to(['s-upload']),
    'id' => 'test',
    'csrf' => true,
    'renderTag' => false,
    'jsOptions' => [
        'width' => 120,
        'height' => 40,
        'onUploadError' => "function(file, errorCode, errorMsg, errorString) {
            console.log('The file ' + file.name + ' could not be uploaded: ' + errorString + errorCode + errorMsg);
        }",
        'onUploadSuccess' => "function(file, data, response) {
            data = JSON.parse(data);
            if (data.error) {
                console.log(data.msg);
            } else {
                console.log(data.fileUrl);
            }
        }"
    ]
]);

//直接渲染
echo Html::activeLabel($model, 'file');
echo Uploadify::widget([
    'url' => yii\helpers\Url::to(['s-upload']),
    'attribute' => 'file',
    'model' => $model,
    'csrf' => true,
    'jsOptions' => [
        'width' => 120,
        'height' => 40,
        'onUploadError' => "function(file, errorCode, errorMsg, errorString) {
        console.log('The file ' + file.name + ' could not be uploaded: ' + errorString + errorCode + errorMsg);
    }",
        'onUploadSuccess' => "function(file, data, response) {
        console.log('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
    }"
    ]
]);
```

Action:
-------

[](#action)

### version 2.0

[](#version-20-1)

---

```
use xj\uploadify\UploadAction;

public function actions() {
    return [
        's-upload' => [
            'class' => UploadAction::className(),
            'basePath' => '@webroot/upload',
            'baseUrl' => '@web/upload',
            'enableCsrf' => true, // default
            'postFieldName' => 'Filedata', // default
            //BEGIN METHOD
            'format' => [$this, 'methodName'],
            //END METHOD
            //BEGIN CLOSURE BY-HASH
            'overwriteIfExist' => true,
            'format' => function (UploadAction $action) {
                $fileext = $action->uploadfile->getExtension();
                $filename = sha1_file($action->uploadfile->tempName);
                return "{$filename}.{$fileext}";
            },
            //END CLOSURE BY-HASH
            //BEGIN CLOSURE BY TIME
            'format' => function (UploadAction $action) {
                $fileext = $action->uploadfile->getExtension();
                $filehash = sha1(uniqid() . time());
                $p1 = substr($filehash, 0, 2);
                $p2 = substr($filehash, 2, 2);
                return "{$p1}/{$p2}/{$filehash}.{$fileext}";
            },
            //END CLOSURE BY TIME
            'validateOptions' => [
                'extensions' => ['jpg', 'png'],
                'maxSize' => 1 * 1024 * 1024, //file size
            ],
            'beforeValidate' => function (UploadAction $action) {
                //throw new Exception('test error');
            },
            'afterValidate' => function (UploadAction $action) {},
            'beforeSave' => function (UploadAction $action) {},
            'afterSave' => function (UploadAction $action) {
                $action->output['fileUrl'] = $action->getWebUrl();
                $action->getFilename(); // "image/yyyymmddtimerand.jpg"
                $action->getWebUrl(); //  "baseUrl + filename, /upload/image/yyyymmddtimerand.jpg"
                $action->getSavePath(); // "/var/www/htdocs/upload/image/yyyymmddtimerand.jpg"
            },
        ],
    ];
}
```

### version 1.0

[](#version-10-1)

---

```
use xj\uploadify\UploadAction;

public function actions() {
    return [
        's-upload' => [
            'class' => UploadAction::className(),
            'uploadBasePath' => '@webroot/upload', //file system path
            'uploadBaseUrl' => '@web/upload', //web path
            'csrf' => true,
//            'format' => 'image/{yyyy}{mm}{dd}/{time}{rand:6}', // OR Closure
            'format' => function(UploadAction $action) {
                $fileext = $action->uploadFileInstance->getExtension();
                $filehash = sha1(uniqid() . time());
                $p1 = substr($filehash, 0, 2);
                $p2 = substr($filehash, 2, 2);
                return "{$p1}/{$p2}/{$filehash}.{$fileext}";
            },
            'validateOptions' => [
                'extensions' => ['jpg', 'png'],
                'maxSize' => 1 * 1024 * 1024, //file size
            ],
            'beforeValidate' => function(UploadAction $action) {},
            'afterValidate' => function(UploadAction $action) {},
            'beforeSave' => function(UploadAction $action) {},
            'afterSave' => function(UploadAction $action) {
                //$action->filename;  //   image/yyyymmdd/xxx.jpg
                //$action->$fullFilename //  /var/www/htdocs/image/yyyymmddtimerand.jpg
            },
        ],
    ];
}
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~28 days

Recently: every ~0 days

Total

9

Last Release

3894d ago

Major Versions

1.0.5 → 2.0.02015-09-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/f9f04ccc1ccda3af80975323425ff7d5f7d142603f1ad05df6558ffa63256f8d?d=identicon)[xjflyttp](/maintainers/xjflyttp)

---

Top Contributors

[![xjflyttp](https://avatars.githubusercontent.com/u/128428?v=4)](https://github.com/xjflyttp "xjflyttp (19 commits)")

### Embed Badge

![Health badge](/badges/xj-yii2-uploadify-widget/health.svg)

```
[![Health](https://phpackages.com/badges/xj-yii2-uploadify-widget/health.svg)](https://phpackages.com/packages/xj-yii2-uploadify-widget)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)

PHPackages © 2026

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