libratechie/flysystem-aliyun 问题修复 & 功能扩展

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

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

libratechie/flysystem-aliyun

Composer 安装命令:

composer require libratechie/flysystem-aliyun

包简介

Aliyun OSS Flysystem Adapter

README 文档

README

Version Tests License

A Flysystem adapter for Aliyun OSS.

Requirements

  • PHP >= 8.2
  • league/flysystem ^3.28
  • aliyuncs/oss-sdk-php ^2.7

Installation

You can install the package via Composer:

composer require libratechie/flysystem-aliyun

Configuration

To use the Aliyun adapter, you need to configure it with your Aliyun OSS credentials and settings.

use League\Flysystem\Filesystem;
use Libratechie\Flysystem\Aliyun\AliyunAdapter;

$accessKeyId = 'your-access-id';
$accessKeySecret = 'your-access-key';
$bucket = 'your-bucket-name';
$endpoint = 'your-endpoint'; // e.g., oss-cn-guangzhou.aliyuncs.com

$adapter = new AliyunAdapter($accessKeyId, $accessKeySecret, $endpoint, $bucket);

$config = [
    'public_url' => 'your-public-url',
    // e.g., https://your-bucket-name.oss-cn-guangzhou.aliyuncs.com
];
$filesystem = new Filesystem($adapter, $config);

Usage

Here are some examples of how to use the filesystem with the Aliyun adapter:

Checking

// Checking if a File Exists
$filesystem->fileExists('path/to/file.txt');

// Checking if a Directory Exists
$filesystem->directoryExists('path/to');

// Checking if a File or Folder Exists
$filesystem->directoryExists('path/to/file.txt');

Write

// Writing a File
$filesystem->write('path/to/file.txt', 'contents');

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

// Create a directory
$filesystem->createDirectory('path/to/directory');

// Move a file
$filesystem->rename('path/to/file.txt', 'new/path/to/file.txt');

// Copy a file
$filesystem->copy('path/to/file.txt', 'new/path/to/file.txt');

Visibility

// Set the visibility of a file to 'public'
$filesystem->setVisibility('path/to/file.txt', 'public');

// Get the visibility of a file
// default: Inherits Bucket permissions. The read/write permissions of individual files are determined by the Bucket's read/write permissions.
// private: Private. All access operations to the file require authentication.
// public-read: Public read. Write operations require authentication, but the file can be read anonymously.
// public-read-write: Public read/write. Anyone (including anonymous visitors) can read and write the file.
$visibility = $filesystem->visibility('path/to/file.txt');

Read

// Listing Contents of a Directory
$contents = $filesystem->listContents('path/to/directory', true);
foreach ($contents as $object) {
    echo $object['type'] . ': ' . $object['path'] . PHP_EOL;
}

// Reading a File
$contents = $filesystem->read('path/to/file.txt');

// Get the last modified time of a file
$lastModified = $filesystem->lastModified('path/to/file.txt');

// Get the file size
$fileSize = $filesystem->fileSize('path/to/file.txt');

// Get the mime type of file
$mimeType = $filesystem->mimeType('path/to/file.txt');

// Assuming 'public_url' is configured in the $config array
// Generate a public URL for a file
$publicUrl = $this->filesystem->publicUrl($path);

// Sign URL with specified expiration time in seconds and HTTP method.
// The signed URL could be used to access the object directly.
$expiresAt = new DateTimeImmutable('+1 hour');
$privateUrl = $this->filesystem->temporaryUrl($path, $expiresAt);

Delete

// Deleting a File
$filesystem->delete('path/to/file.txt');

// Deleting a Directory
$filesystem->deleteDirectory('path/to');

libratechie/flysystem-aliyun 适用场景与选型建议

libratechie/flysystem-aliyun 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 libratechie/flysystem-aliyun 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 libratechie/flysystem-aliyun 我们能提供哪些服务?
定制开发 / 二次开发

基于 libratechie/flysystem-aliyun 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 13
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-07