PHP code example of enochzg / yii2-aliyun-oss

1. Go to this page and download the library: Download enochzg/yii2-aliyun-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/ */

    

enochzg / yii2-aliyun-oss example snippets




  'aliyun' => [
    'class' => 'enochzg\aliyun\Aliyun',
    'accessKeyId' => '',  //在阿里云的控制台可以创建、查询
    'accessSecret' => '',   //在阿里云的控制台可以创建、查询
    'defaultRoleArn' => '',   //在阿里云的控制台可以创建、查询
    'defaultBucketName' => '',  //默认操作哪个BucketName
    'endPoint' => 'oss-cn-shenzhen.aliyuncs.com',
  ],
  


  
  //生成临时授权凭证
  $sessionName = '99';
  $durationSeconds = 3600; //过期时间
  $token = yii::$app->aliyun->generateSTSToken($sessionName, $durationSeconds);
  
  //上传文件,默认操作defaultBucketName
  yii::$app->aliyun->uploadFile('enoch-test', '/home/enoch/图片/2.png');
  
  //单个文件删除,默认操作defaultBucketName
  yii::$app->aliyun->deleteObject('object-name', 'bucketName');
  
  //批量删除文件,默认操作defaultBucketName
  yii::$app->aliyun->deleteObjects(['path/58ca9c-f', 'path/929171a3']);