PHPackages                             yiiplus/yii2-storage - 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. yiiplus/yii2-storage

ActiveProject

yiiplus/yii2-storage
====================

YiiPlus Storage

v1.1.2(6y ago)25532BSD-3-ClausePHPPHP &gt;=7.1.0CI failing

Since May 28Pushed 6y ago2 watchersCompare

[ Source](https://github.com/yiiplus/yii2-storage)[ Packagist](https://packagist.org/packages/yiiplus/yii2-storage)[ RSS](/packages/yiiplus-yii2-storage/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (5)Versions (14)Used By (0)

storage storage
===============

[](#storage-storage)

该套件基于yiiplus，旨在自动执行上传文件，保存和存储的常规过程,存储集成本地存储、阿里云OSS、腾讯云COS

版本
--

[](#版本)

版本时间1.02019年5月1日特点
--

[](#特点)

- 文件上传小部件（基于Blueimp文件上传）
- 用于存储文件的组件（构建在flysystem之上）
- 上传方式包括通过接口文件上传，图片base64上传

平台支持
----

[](#平台支持)

支持平台资费本地无阿里云[费用](https://common-buy.aliyun.com/?spm=5176.7933691.1309819..58f92a66AqB8vY&commodityCode=ossbag&request=%7B%22region%22%3A%22china-common%22%7D#/buy)腾讯云[费用](https://buy.cloud.tencent.com/cos)安装
--

[](#安装)

通过composer安装

```
composer require yiiplus/yii2-storage "^1.1.2"
```

或添加配置到项目目录下的composer.json

```
"require": {
...
"yiiplus/yii2-storage": "^1.1.2",
...
}

```

配置
--

[](#配置)

在组件配置中配置

- 本地上传

```
'storage'=>[
'class' => 'yiiplus\storage\Storage',
'baseUrl' => '@web/uploads',  //本地用文件在项目存储目录 三方用可访问到文件的域名
'basePath' => 'image', //配置上传根目录
'openDirIndex' => 1, //是否开启文件索引 可不配置
'filesystem'=> [
        'class' => 'yiiplus\storage\filesystem\LocalFilesystemBuilder',  //文件处理方式
        'path' => '@root/web/backend/uploads/'    //上传路径
    ]
],
```

- 阿里云上传

```
'storage'=>[
'class' => 'yiiplus\storage\Storage',
'basePath' => 'image', //配置上传根目录
'baseUrl' => '@web/uploads',  //本地用文件在项目存储目录 三方用可访问到文件的域名
'filesystem'=> [
        'class' => 'yiiplus\storage\filesystem\OssFilesystemBuilder',  //文件处理方式
        'accessId' => '',  //密钥id
        'accessSecret' => '', //密钥key
        'bucket' => '', //桶名
        'endpoint' => '' //节点
    ]
],
```

- 腾讯云上传

```
'storage'=>[
'class' => 'yiiplus\storage\Storage',
'basePath' => 'image', //配置上传根目录
'baseUrl' => '@web/uploads',  //本地用文件在项目存储目录 三方用可访问到文件的域名
'filesystem'=> [
        'class' => 'yiiplus\storage\filesystem\CosFilesystemBuilder',  //文件处理方式
        'secretId' => '',//cos秘钥id
        'secretKey' => '',//秘钥key
        'bucket' => '',//桶名
        'appId' => '',//appId
        'region' => '',//地区
    ]
],
```

后台上传
====

[](#后台上传)

动作
--

[](#动作)

可选动作说明upload上传delete删除### 上传动作

[](#上传动作)

```
public function actions(){
    return [
        'upload'=>[
            //上传类空间
            'class'=>'yiiplus\storage\actions\UploadAction',
            //是否返回多个文件
            'multiple' => true,
            //是否禁用csrf
            'disableCsrf' => true,
            //删除路由
            'deleteRoute' => 'delete',
            'sessionKey' => '_uploadedFiles',
            //实例化的容器名
            'fileStorage' => 'storage',
            //校验规则
            'validationRules' => [],
            //保存成功后处理
            'on afterSave' => function($event) {
                $file = $event->path;
            }
        ]
    ];
}
```

### 删除动作

[](#删除动作)

```
public function actions(){
    return [
        'delete'=>[
            'class'=>'yiiplus\storage\actions\DeleteAction',
        ]
    ];
}
```

上传组件
----

[](#上传组件)

- 独立使用

```
echo yiiplus\storage\widget\Upload::widget([
    //模型
    'model' => $searchModel,
    //字段名
    'attribute' => 'username',
    //提交路径
    'url' => ['upload'],
    //上传文件路径
    'uploadPath' => 'subfolder',
    //是否排序
    'sortable' => true,
    //文件最大限制 10M
    'maxFileSize' => 10 * 1024 * 1024,
    //文件最小限制
    'minFileSize' => 1kb,
    //文件数量 默认1个
    'maxNumberOfFiles' => 1,
    //文件后缀限制 正则
    'acceptFileTypes' => new JsExpression('/(\.|\/)(gif|jpe?g|png)$/i'),
    //是否显示文件预览名
    'showPreviewFilename' => true,
    //其他blueimp选项
    'clientOptions' => []
]);
```

- 独立使用 不使用模型

```
echo yiiplus\storage\widget\Upload::widget([
    'name' => 'filename',
    'hiddenInputId' => 'filename',
    'url' => ['upload'],
    'uploadPath' => 'subfolder',
    'sortable' => true,
    'maxFileSize' => 10 * 1024 * 1024,
    'minFileSize' => 1,
    'maxNumberOfFiles' => 3,
    'acceptFileTypes' => new JsExpression('/(\.|\/)(gif|jpe?g|png)$/i'),
    'showPreviewFilename' => false,
    'clientOptions' => []
]);
```

- activeForm中使用

data

```
$model->files = [
  [
      //文件名称(可选)
      'name' => '123.jpg',
      //文件大小(可选)
      'size' => '9090',
      //文件路径(可选)
      'url' => '',
      //缩略图路径(可选)
      'thumbnailUrl' => '',
      //删除路由(可选)
      'deleteUrl' => 'delete',
      //删除类型(可选)
      'deleteType' => 'DELETE',
  ]
];
```

view

```
echo $form->field($model, 'files')->widget(
    'yiiplus\storage\widget\Upload',
    [
        'url' => ['upload'],
        'uploadPath' => 'subfolder',
        'sortable' => true,
        'maxFileSize' => 10 * 1024 * 1024, // 10 MiB
        'maxNumberOfFiles' => 3,
        'clientOptions' => []
    ]
);
```

### 上传Widget事件

[](#上传widget事件)

上传小部件会触发一些内置的blueimp事件： 您可以直接使用它们，也可以在选项中添加自定义处理程序

```
'clientOptions' => [
    'start' => new JsExpression('function(e, data) { ... do something ... }'),//开始
    'done' => new JsExpression('function(e, data) { ... do something ... }'),//完成
    'fail' => new JsExpression('function(e, data) { ... do something ... }'),//失败
    'always' => new JsExpression('function(e, data) { ... do something ... }'),//总是
]
```

API
===

[](#api)

- 文件方式

```
$file = UploadedFile::getInstanceByName('file');
$s = Yii::$app->storage;
$result = $s->save($file, 'avatar');
return Yii::$app->storage->baseUrl . $result;
```

###  Health Score

30

—

LowBetter than 67% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

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

Total

12

Last Release

2454d ago

### Community

Maintainers

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

---

Top Contributors

[![zhangxueee](https://avatars.githubusercontent.com/u/42345684?v=4)](https://github.com/zhangxueee "zhangxueee (3 commits)")

### Embed Badge

![Health badge](/badges/yiiplus-yii2-storage/health.svg)

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

PHPackages © 2026

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