BunnyCDN.PHP.Storage
3.4.0
Pustaka PHP resmi yang digunakan untuk berinteraksi dengan BunnyCDN Storage API.
composer require bunnycdn/storage
Buat instance BunnyStorageClient
dengan detail autentikasi
$ client = new Bunny Storage Client ( ' access-key ' , ' storage-zone ' , Bunny Storage Region :: SINGAPORE );
Konstruktor BunnyCDNStorage mengambil parameter berikut:
$ client -> upload ( ' /path/to/local/file.txt ' , ' remote/path/hello-world.txt ' );
Checksum dapat dinonaktifkan menggunakan parameter $withChecksum
:
$ client -> upload ( ' /path/to/local/file.txt ' , ' remote/path/hello-world.txt ' , false );
Catatan
Unggahan asinkron didukung dengan $client->uploadAsync()
. Ini akan mengembalikan GuzzleHttpPromisePromiseInterface
.
$ client -> download ( ' remote/path/hello-world.txt ' , ' /path/to/local/file.txt ' );
$ items = $ client -> listFiles ( ' remote/path/ ' );
Mengembalikan array objek FileInfo.
$ item = $ client -> info ( ' remote/path/hello-world.txt ' );
Mengembalikan contoh 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 );
Checksum dapat dinonaktifkan menggunakan parameter $withChecksum
:
$ content = ' Hello, world! ' ;
$ client -> putContents ( ' hello-world.txt ' , $ content , false );
$ content = $ client -> getContents ( ' hello-world.txt ' );
echo $ content ; // Hello, world!