yiier/yii2-aliyun-oss 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

yiier/yii2-aliyun-oss

最新稳定版本:1.0

Composer 安装命令:

composer require yiier/yii2-aliyun-oss

包简介

Yii2 阿里云 OSS

README 文档

README

Yii2 阿里云 OSS

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiier/yii2-aliyun-oss "*"

or add

"yiier/yii2-aliyun-oss": "*"

to the require section of your composer.json file.

Usage

配置文件添加组件 :

components => [
    'oss' => [
        'class' => 'yiier\AliyunOSS\OSS',
        'accessKeyId' => 'xxxxx', // 阿里云OSS AccessKeyID
        'accessKeySecret' => 'xxxx', // 阿里云OSS AccessKeySecret
        'bucket' => 'xxx', // 阿里云的bucket空间
        'lanDomain' => 'oss-cn-hangzhou-internal.aliyuncs.com', // OSS内网地址
        'wanDomain' => 'oss-cn-hangzhou.aliyuncs.com', //OSS外网地址
        'isInternal' => true // 上传文件是否使用内网,免流量费(选填,默认 false 是外网)
    ],
]
/** @var \yiier\AliyunOSS\OSS $oss */
$oss = \Yii::$app->get('oss');
$fh = '/vagrant/php/baseapi/web/storage/image/824edb4e295892aedb8c49e4706606d6.png';
$oss->upload('824edb4e295892aedb8c49e4706606d6.png', $fh);

或者

$oss->upload('storage/image/824edb4e295892aedb8c49e4706606d6.png', $fh); // 会自动创建文件夹

其他用法

$oss->createDir('storage/image/'); //创建文件夹
$oss->delete('824edb4e295892aedb8c49e4706606d6.png'); // 删除文件
$oss->delete('storage/image/824edb4e295892aedb8c49e4706606d6.png'); // 删除文件,如果这个文件是此文件夹的最后一个文件,则会把文件夹一起删除
$oss->delete('storage/image/'); // 删除文件夹,但是要确保是空文件夹
$oss->getAllObject(); // 获取根目录下的所有文件名,默认是100个
$oss->getAllObject(['prefix' => 'storage/image/']); // 获取 `storage/image/` 目录下的所有文件名,默认是100个

Upload action

视图文件:

<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
    <?= $form->field($model, 'images[]')->fileInput() ?>
    <div class="form-group">
        <?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
    </div>
<?php ActiveForm::end(); ?>

控制器:

namespace admin\controllers;

use yii\web\Controller;
use yiier\AliyunOSS\FileUploadAction;

class FileController extends Controller
{
    public function actions()
    {
        return [
            'upload-images' => [
                'class' => FileUploadAction::class,
                'fileParam' => 'images',
                'keepLocalFile' => true, // default false
                'savePath' => '@webroot/uploads',
                'webPath' => '@web/uploads',
            ],
        ];
    }
}

PS:请求的参数 images 值是个数组

统计信息

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

GitHub 信息

  • Stars: 43
  • Watchers: 3
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-03-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固