fiberphp/storage

There is no license information available for the latest version (dev-master) of this package.

📁 FiberPHP 存储抽象 —— 统一文件系统接口,支持本地/OSS/COS/S3 兼容驱动。

Maintainers

Package info

gitee.com/FiberPHP/storage

Issues

pkg:composer/fiberphp/storage

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

dev-master 2026-08-23 16:17 UTC

This package is auto-updated.

Last update: 2026-08-23 16:18:08 UTC


README

FiberPHP 对象存储组件,支持本地文件系统、阿里云 OSS、腾讯云 COS、Amazon S3。

安装

composer require fiberphp/storage

配置

安装后会自动生成 config/storage/app.php 配置文件:

return [
    'enable'  => true,
    'default' => 'local',
    'disks'   => [
        'local' => [
            'driver' => 'local',
            'root'   => public_path() . '/uploads',
            'url'    => '',
        ],
        'public' => [
            'driver' => 'local',
            'root'   => public_path() . '/storage',
            'url'    => '/storage',
        ],
        'oss' => [
            'driver'          => 'oss',
            'access_key_id'   => '',
            'access_key_secret'=> '',
            'bucket'          => '',
            'endpoint'        => 'oss-cn-hangzhou.aliyuncs.com',
            'region'          => 'oss-cn-hangzhou',
            'is_cname'        => false,
            'ssl'             => true,
            'prefix'          => '',
        ],
        'cos' => [
            'driver'          => 'cos',
            'secret_id'       => '',
            'secret_key'      => '',
            'bucket'          => '',
            'region'          => 'ap-guangzhou',
            'app_id'          => '',
            'ssl'             => true,
            'prefix'          => '',
        ],
        's3' => [
            'driver'          => 's3',
            'key'             => '',
            'secret'          => '',
            'bucket'          => '',
            'region'          => 'us-east-1',
            'endpoint'        => '',
            'version'         => 'latest',
            'use_path_style'  => false,
            'prefix'          => '',
        ],
    ],
];

使用

基本操作

use FiberPHP\Storage\Storage;

// 写入文件
Storage::put('path/file.txt', 'contents');

// 写入上传的文件
Storage::putFile('path', $uploadFile);

// 读取文件
$contents = Storage::get('path/file.txt');

// 下载文件
Storage::download('path/file.txt', 'local-path/file.txt');

// 删除文件
Storage::delete('path/file.txt');

// 判断是否存在
$exists = Storage::exists('path/file.txt');

// 获取文件元信息
$stat = Storage::stat('path/file.txt');

// 获取访问 URL
$url = Storage::url('path/file.txt');

// 列出目录
$files = Storage::list('path/');

// 创建目录
Storage::makeDir('path/dir');

// 复制文件
Storage::copy('from/file.txt', 'to/file.txt');

// 移动文件
Storage::move('from/file.txt', 'to/file.txt');

使用不同的磁盘

Storage::disk('oss')->put('path/file.txt', 'contents');
Storage::disk('cos')->get('path/file.txt');
Storage::disk('s3')->delete('path/file.txt');