xxtime/flysystem-aliyun-oss

flysystem 的 AliYun OSS 适配器。支持 PHP8。依赖 aliyuncs/oss-sdk-php ~2.6

1.7.1 2023-12-11 08:40 UTC

This package is auto-updated.

Last update: 2024-09-11 10:08:44 UTC


README

Latest Stable Version Build Status Total Downloads License Author Code Climate

AliYun OSS 存储适配器 for flysystem - PHP 文件系统抽象。

安装

composer require xxtime/flysystem-aliyun-oss

日志

1.3.0
  1. 某些参数名称已更改
  2. 默认区域 oss-cn-hangzhou
1.7.0
  1. 支持 flysystem v3
  2. 支持 oss-sdk-php 2.6
  3. 支持 PHP8

用法

use League\Flysystem\Filesystem;
use Xxtime\Flysystem\Aliyun\OssAdapter;

$aliyun = new OssAdapter([
    'accessId'       => '<aliyun access id>',
    'accessSecret'   => '<aliyun access secret>',
    'bucket'         => '<bucket name>',
    'endpoint'       => '<endpoint address>',
    // 'timeout'        => 3600,
    // 'connectTimeout' => 10,
    // 'isCName'        => false,
    // 'token'          => '',
]);
$filesystem = new Filesystem($aliyun);


// Write Files
$filesystem->write('path/to/file.txt', 'contents');
// get RAW data from aliYun OSS
$raw = $aliyun->supports->getFlashData();

// Write Use writeStream
$stream = fopen('local/path/to/file.txt', 'r+');
$filesystem->writeStream('path/to/file.txt', $stream);

// Update Files
$filesystem->update('path/to/file.txt', 'new contents');

// Check if a file exists
$exists = $filesystem->has('path/to/file.txt');

// Read Files
$contents = $filesystem->read('path/to/file.txt');

// Delete Files
$filesystem->delete('path/to/file.txt');

// Rename Files
$filesystem->rename('filename.txt', 'newname.txt');

// Copy Files
$filesystem->copy('filename.txt', 'duplicate.txt');


// list the contents (not support recursive now)
$filesystem->listContents('path', false);
// 说明:此方法返回从阿里云接口返回的原生数据,仅可调用一次
// DESC: this function return AliYun RAW data
$raw = $aliyun->supports->getFlashData();

文档

  1. 区域和端点表
  2. 阿里云 OSS PHP SDK 文档

参考

http://flysystem.thephpleague.com/api/
https://github.com/thephpleague/flysystem