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

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

huijiewei/yii2-upload
=====================

A upload component for Yii2.

4.0.0(1y ago)332811MITPHPPHP &gt;=8.0.2

Since Mar 24Pushed 1y ago2 watchersCompare

[ Source](https://github.com/huijiewei/yii2-upload)[ Packagist](https://packagist.org/packages/huijiewei/yii2-upload)[ Docs](https://github.com/huijiewei/yii2-upload.git)[ RSS](/packages/huijiewei-yii2-upload/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (5)Versions (22)Used By (1)

yii2-upload
===========

[](#yii2-upload)

`Yii2` 下的一个上传组件, 支持直传到第三方云存储。

安装
--

[](#安装)

```
composer require huijiewei/yii2-upload
```

配置及使用
-----

[](#配置及使用)

### 本地存储

[](#本地存储)

```
    // 在 Yii2 components 配置里面增加

    'upload' => [
        'class' => \huijiewei\upload\drivers\LocalFile::class,
        'path' => '文件上传的目录',
        'uploadAction' => 'site/upload-file',
        'cropAction' => 'site/crop-image'
    ]

    // 根据上面的 action 配置，在对应的控制器里面增加

    public function actions()
    {
        return [
            'upload-file' => [
                'class' => \huijiewei\upload\UploadAction::class,
            ],
            'crop-image' => [
                'class' => \huijiewei\upload\ImageCropAction::class,
            ]
        ];
    }

    // 使用 widgets 命名空间下的 widget

    \huijiewei\upload\widgets\FileUploadWidget::widget([
        'name' => 'file',
        'value' => '',
    ]);

    \huijiewei\upload\widgets\ImageUploadWidget::widget([
        'name' => 'image',
        'value' => '',
    ]);

    // 支持多文件

    \huijiewei\upload\widgets\FileUploadWidget::widget([
        'name' => 'files[]',
        'value' => [],
        'multiple' => true
    ]);

    // 云存储支持图片样式

    \huijiewei\upload\widgets\ImageUploadWidget::widget([
        'name' => 'image',
        'value' => '',
        'imageStyleName' => '200x200' // 因为需要和本地切图兼容所以只支持 WxH 格式的样式名称
    ]);

    // 本地存储支持图片切割功能

    \huijiewei\upload\widgets\ImageUploadWidget::widget([
        'name' => 'image',
        'value' => '',
        'cropImage' => [
            'ratio' => 1,
            'size' => [100,100]
        ]
    ]);
```

### 云存储

[](#云存储)

```
    // 阿里云 OSS

    'upload' => [
        'class' => \huijiewei\upload\drivers\AliyunOSS::class,
        'accessKeyId' => '',
        'accessKeySecret' => '',
        'endpoint' => '',
        'bucket' => '',
        'folder' => ''
    ],

    // 腾讯云 COS

     'upload' => [
        'class' => \huijiewei\upload\drivers\TencentCOS::class,
        'appId' => '',
        'secretId' => '',
        'secretKey' => '',
        'bucket' => '',
        'region' => '',
        'folder' => '',
    ],

    // 七牛

     'upload' => [
        'class' => \huijiewei\upload\drivers\Qiniu::class,
        'accessKey' => '',
        'secretKey' => '',
        'bucket' => '',
        'folder' => '',
        'uploadHost' => '',
        'bucketHost' => '',
        'bucketHttps' => false,
    ],
```

### componentId 自定义

[](#componentid-自定义)

如果想要使用多个存储引擎，可以定义不同的 componentId

然后设置 widget 和 action 的 uploadDriver 属性为对应的 componentId 即可

直传到云存储
------

[](#直传到云存储)

该组件支持直传到第三方云存储，实际上就是模拟了表单上传的方式。从流程上来说相比于传统的先上传到服务器，再从服务器传到云存储来说，少了一步转发。从架构上来说，原来的上传都统一走网站服务器，上传量过大时，瓶颈在网站服务器，可能需要扩容网站服务器。采用表单上传后，上传都是直接从客户端发送到云存储。上传量过大时，压力都在云存储上，由云存储来保障服务质量。

目前支持的第三方云储存： `本地(LocalFile)` `腾讯云(TencentCOS)` `阿里云(AliyunOSS)` `七牛(Qiniu)`

> 其中的本地不算云存储，只是标识仍旧支持本地磁盘存储。

扩展
--

[](#扩展)

当然，你也可以拓展支持的云存储，继承 BaseUpload 并实现对应的方法即可

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity75

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

Recently: every ~383 days

Total

21

Last Release

606d ago

Major Versions

2.1.5 → 3.0.12020-04-09

3.0.7 → 4.0.02024-10-29

PHP version history (2 changes)2.0.1PHP ^7.1.3

4.0.0PHP &gt;=8.0.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7017860?v=4)[Huijie Wei](/maintainers/huijiewei)[@huijiewei](https://github.com/huijiewei)

---

Top Contributors

[![huijiewei](https://avatars.githubusercontent.com/u/7017860?v=4)](https://github.com/huijiewei "huijiewei (34 commits)")

---

Tags

yii2extensionassetsuploader

### Embed Badge

![Health badge](/badges/huijiewei-yii2-upload/health.svg)

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

###  Alternatives

[budyaga/yii2-cropper

Yii-Framework widget for uploading and cropping images

4370.1k4](/packages/budyaga-yii2-cropper)[liyunfang/yii2-upload-behavior

Upload behavior for Yii 2

161.7k](/packages/liyunfang-yii2-upload-behavior)

PHPackages © 2026

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