shopwwi / filesystem-oss
AliYun OSS adapter for flysystem V2. aliyuncs/oss-sdk-php ~2.4
Installs: 1 697
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 1
Open Issues: 0
Requires
- php: >=7.3
- aliyuncs/oss-sdk-php: ^2.4
- league/flysystem: ^2.1|^3.0
README
#安装
composer require shopwwi/filesystem-oss
#感谢
借鉴了 xxtime/flysystem-aliyun-oss 部分代码,在此表示感谢。
Usage
use League\Flysystem\Filesystem;
use Shopwwi\FilesystemOss\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+');
$result = $filesystem->writeStream('path/to/file.txt', $stream);
if (is_resource($stream)) {
fclose($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);