All Projects → yiier → yii2-aliyun-oss

yiier / yii2-aliyun-oss

Licence: other
Yii2 Aliyun OSS Yii2 阿里云 OSS

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to yii2-aliyun-oss

oss-rust-sdk
Aliyun OSS SDK for Rust
Stars: ✭ 59 (+43.9%)
Mutual labels:  oss, aliyun-oss
aliyun-oss-deploy
🙈 一个 nodejs 命令行工具,用于部署静态资源到 aliyun oss,支持代码方式和 CLI 方式!
Stars: ✭ 31 (-24.39%)
Mutual labels:  oss, aliyun-oss
Ali Oss
Aliyun OSS(open storage service) JavaScript SDK for the browser and Node.js
Stars: ✭ 1,579 (+3751.22%)
Mutual labels:  oss, aliyun-oss
IconPacks.Browser
The Browser for all available Icon packages from MahApps.Metro.IconPacks
Stars: ✭ 74 (+80.49%)
Mutual labels:  oss
FactoryOrchestrator
A cross-platform system service which provides a simple way to run and manage factory line validation, developer inner-loop, diagnostics, and fault analysis workflows.
Stars: ✭ 36 (-12.2%)
Mutual labels:  oss
ar-search
Provides unified search model for Yii ActiveRecord
Stars: ✭ 31 (-24.39%)
Mutual labels:  yii2-extension
android-oss-best-practices
Best practices on creating Android OSS library projects [JA]
Stars: ✭ 32 (-21.95%)
Mutual labels:  oss
yii2-stat
Yii2 Multi Web Statistic Module (yametrika, google-analytic, own db-counter)
Stars: ✭ 18 (-56.1%)
Mutual labels:  yii2-extension
yii2-pgsql
Improved PostgreSQL schemas for Yii2
Stars: ✭ 34 (-17.07%)
Mutual labels:  yii2-extension
mall4cloud
⭐️⭐️⭐️ Springcloud商城 O2O商城 小程序商城 PC商城 H5商城 APP商城 Java商城 分销商城 多用户商城 uniapp商城 微服务商城
Stars: ✭ 3,915 (+9448.78%)
Mutual labels:  oss
yii2-newsletter
Module for saving user contacts from newsletter form to database
Stars: ✭ 17 (-58.54%)
Mutual labels:  yii2-extension
elections-api
Serving JSON for all elections since 1992
Stars: ✭ 16 (-60.98%)
Mutual labels:  oss
yii2-cashier
Yii2 Cashier provides an interface to Stripe's subscription billing services.
Stars: ✭ 43 (+4.88%)
Mutual labels:  yii2-extension
portal-web-legacy
The web client for the JOSA portal.
Stars: ✭ 15 (-63.41%)
Mutual labels:  oss
aliyun-oss-laravel
Laravel 的 Aliyun OSS 扩展, 支持 Laravel 9. Alibaba Cloud Object Storage Service For Laravel.
Stars: ✭ 91 (+121.95%)
Mutual labels:  oss
fossresponders.com
The website for FOSS Responders
Stars: ✭ 20 (-51.22%)
Mutual labels:  oss
terraform-provider-graylog
Terraform Provider for Graylog
Stars: ✭ 21 (-48.78%)
Mutual labels:  oss
spring-boot-learn-box
spring boot集成其他组件
Stars: ✭ 21 (-48.78%)
Mutual labels:  oss
trace-cocoa-sdk
Catch bugs before they reach production — get detailed crash reports and monitor how your app is performing across the entire install base.
Stars: ✭ 15 (-63.41%)
Mutual labels:  oss
RuoYi-Vue-Plus
基于RuoYi-Vue集成 Lombok+Mybatis-Plus+Undertow+knife4j+Hutool+Feign 重写所有原生业务 定期与RuoYi-Vue同步
Stars: ✭ 110 (+168.29%)
Mutual labels:  oss

Yii2 Aliyun OSS

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 值是个数组

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].