BunnyCDN.PHP.Storage
3.4.0
用于与 BunnyCDN 存储 API 交互的官方 PHP 库。
composer require bunnycdn/storage
使用身份验证详细信息创建BunnyStorageClient
的实例
$ client = new Bunny Storage Client ( ' access-key ' , ' storage-zone ' , Bunny Storage Region :: SINGAPORE );
BunnyCDNStorage 构造函数采用以下参数:
$ client -> upload ( ' /path/to/local/file.txt ' , ' remote/path/hello-world.txt ' );
可以使用$withChecksum
参数禁用校验和:
$ client -> upload ( ' /path/to/local/file.txt ' , ' remote/path/hello-world.txt ' , false );
笔记
$client->uploadAsync()
支持异步上传。它将返回一个GuzzleHttpPromisePromiseInterface
。
$ client -> download ( ' remote/path/hello-world.txt ' , ' /path/to/local/file.txt ' );
$ items = $ client -> listFiles ( ' remote/path/ ' );
返回 FileInfo 对象的数组。
$ item = $ client -> info ( ' remote/path/hello-world.txt ' );
返回 FileInfo 的实例。
$ client -> delete ( ' remote/path/hello-world.txt ' );
$ errors = $ client -> deleteMultiple ([ ' file1.txt ' , ' file2.txt ' , ' non-existing.txt ' ]);
var_dump ( $ errors );
/*
array(1) {
'non-existing.txt' =>
string(16) "Object not found"
}
*/
$ content = ' Hello, world! ' ;
$ client -> putContents ( ' hello-world.txt ' , $ content );
可以使用$withChecksum
参数禁用校验和:
$ content = ' Hello, world! ' ;
$ client -> putContents ( ' hello-world.txt ' , $ content , false );
$ content = $ client -> getContents ( ' hello-world.txt ' );
echo $ content ; // Hello, world!