PHP code example of thanatosxia / yii2-oss

1. Go to this page and download the library: Download thanatosxia/yii2-oss library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thanatosxia / yii2-oss example snippets


'oss' => [
    'class' => 'thanatos\oss\Oss',
    'accessKeyId' => '', // Your accessKeyId
    'accessKeySecret' => '', // Your accessKeySecret
    'endpoint' => '', // endpoint address
    'bucket' => '', // Bucket Name
],

/**
 * $object 目标文件名
 * $content 二进制文件内容
 * $options 其它参数
 */
Yii::$app->oss->putObject($object, $content, $options);

/**
 * $object 目标文件名
 * $options 其它参数
 */
Yii::$app->oss->deleteObject($object, $options);

Yii::$app->oss->putObjectOrigin($object, $url, $options);

// 配置文件中增加一下选项
'oss' => [
    'accessKeyId' => 'xxxx',
    'accessKeySecret' => 'xxxx',
    'endpoint' => 'xxx',
    'bucket' => '',
    'callbackUrl' => '上传成功OSS请求的路径',
    // 自定义的上传回掉的参数
    'callbackParams' => [
        'user_id',
        'method',
        'folder_id'
    ]
],

// 获取OSS 签名 (dir 是允许前端上传的目录前缀)
return Yii::$app->oss->getSignature($dir);

$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
$ossClient->putObject($bucket, $object, $content);

Yii::$app->oss->putObject($object, $content, $options);

Yii::$app->oss->setBucket($bucket);
Yii::$app->oss->putObject($object, $content, $options);