xinningsu/thinkphp-filesystem-baidu-bos

Baidu BOS storage for ThinkPHP, 百度对象存储作为ThinkPHP文件存储。

v1.0.0 2025-08-14 00:44 UTC

This package is auto-updated.

Last update: 2025-08-14 01:01:55 UTC


README

Baidu BOS storage for ThinkPHP, 百度对象存储作为ThinkPHP文件存储。

MIT licensed Build Status Code Coverage Scrutinizer Code Quality Code Intelligence Status

安装

composer require xinningsu/thinkphp-filesystem-baidu-bos

配置

config/filesystem.php 中添加配置:

return [
    // 默认磁盘
    'default' => 'bos', // 默认使用百度对象存储,或操作时指定 Filesystem::disk('bos')
    // 磁盘列表
    'disks'   => [
        // ...
        // 百度对象存储
        'bos' => [
            'type'       => 'bos',
            'access_key' => 'your_access_key',
            'secret_key' => 'your_secret_key',
            'region'     => 'your_region',
            'bucket'     => 'your_bucket',
        ],
        // ...
    ],
];

例子

use think\facade\Filesystem;

// Write a new file.
Filesystem::write('file.txt', 'contents');

// If the default disk is not BOS, you can specify bos disk
Filesystem::disk('bos')->write('file.txt', 'contents');

// Write a new file using a stream.
Filesystem::writeStream('file.txt', fopen('/resource.txt', 'r'));

// Create a file or update if exists.
Filesystem::put('file.txt', 'contents');

// Create a file or update if exists using a stream.
Filesystem::putStream('file.txt', fopen('/resource.txt', 'r'));

// Update an existing file.
Filesystem::update('file.txt', 'contents');

// Update an existing file using a stream.
Filesystem::updateStream('file.txt', fopen('/resource.txt', 'r'));

// Read a file.
$content = Filesystem::read('file.txt');

// Retrieves a read-stream for a path.
$stream = Filesystem::readStream('file.txt');

// Check whether a file exists.
$has = Filesystem::has('file.txt');

// Copy a file.
Filesystem::copy('file.txt', 'file2.txt');

// Rename a file.
Filesystem::rename('file.txt', 'file2.txt');

// Delete a file.
Filesystem::delete('file.txt');

// Get a file's metadata.
$meta = Filesystem::getMetadata('file.txt');

// Get a file's size.
$size = Filesystem::getSize('file.txt');

// Get a file's mime-type.
$mimeType = Filesystem::getMimetype('file.txt');

// Get a file's timestamp.
$ts = Filesystem::getTimestamp('file.txt');

// Set the visibility for a file.
Filesystem::setVisibility('file.txt', 'public');

// Get a file's visibility.
$visibility = Filesystem::getVisibility('file.txt');

// Delete a directory.
Filesystem::deleteDir('test/');

// Create a directory.
Filesystem::createDir('test/');

// List contents of a directory.
$lists = Filesystem::listContents('test/', true);

Reference

License

MIT