定制 years/yii2-storage 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

years/yii2-storage

Composer 安装命令:

composer require years/yii2-storage

包简介

Resource (Cloud) Storage SDK for Yii2

README 文档

README

This package is one ActiveRecord behavior. It allows you to keep the uploaded file as-is. It support multiple attributes and files.

Based on Flysystem, qiniu and oss supported.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist years/yii2-storage "*"

or add

"years/yii2-storage": "*"

to the require section of your composer.json.

Configuration

Add component 'storage'

'components' => [
        'storage' => [
            'class' => 'years\storage\Storage',
        ],
   ]

Add key filesystems to params.php

return [
	 xxxxx
    'filesystems' => [
    	'default' => 'qiniu',
    	'disks' => [
        	'local' => [
            	'driver' => 'local',
            	'root' => '@webroot/upload',
        	],

        	's3' => [
            	'driver' => 's3',
            	'key' => 'your-key',
            	'secret' => 'your-secret',
            	'region' => 'your-region',
            	'bucket' => 'your-bucket',
        	],

        	'qiniu' => [
            	'driver'  => 'qiniu',
            	'domains' => [
                	'default'   => 'olys54us5.bkt.clouddn.com', //你的七牛域名
                	'https'     => '',         //你的HTTPS域名
                	'custom'    => '',                //你的自定义域名
            	],
            	'access_key'=> 'xxxxx-BCT2',  //AccessKey
            	'secret_key'=> 'xxxx',  //SecretKey
            	'bucket'    => 'xxx',  //Bucket名字
            	'notify_url'=> '',  //持久化处理回调地址
        	],

        	'oss' => [
                'driver'        => 'oss',
                'access_id'     => 'xxxx',
                'access_key'    => 'xxx',
                'bucket'        => 'xxx',
                'endpoint'      => 'oss-cn-hangzhou-internal.aliyuncs.com',
                'isCName'       => false,
                'debug'         => true
        	],
   	 	],
    ],
];


UploadBehavior

This behavior allow you to add file uploading logic with ActiveRecord behavior.

Usage

Attach the behavior to your model class:

public function behaviors()
{
    return [
        [
            'class' => '\years\storage\behaviors\UploadBehavior',
            'attributes' => 'avatar',
            'disk' => 'qiniu',
            'directory' => 'images',
        ],
    ];
}

Add validation rule:

public function rules()
{
    return [
        ['avatar', 'file'],   
    ];
}

Setup proper form enctype:

$form = \yii\bootstrap\ActiveForm::begin([
    'enableClientValidation' => false,
    'options' => [
        'enctype' => 'multipart/form-data',
    ],
]);

File should be uploading fine.

Licence

MIT

统计信息

  • 总下载量: 36
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固