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!