BunnyCDN.PHP.Storage
3.4.0
A biblioteca PHP oficial usada para interagir com a API de armazenamento BunnyCDN.
composer require bunnycdn/storage
Crie uma instância de BunnyStorageClient
com os detalhes de autenticação
$ client = new Bunny Storage Client ( ' access-key ' , ' storage-zone ' , Bunny Storage Region :: SINGAPORE );
O construtor BunnyCDNStorage usa os seguintes parâmetros:
$ client -> upload ( ' /path/to/local/file.txt ' , ' remote/path/hello-world.txt ' );
A soma de verificação pode ser desabilitada usando o parâmetro $withChecksum
:
$ client -> upload ( ' /path/to/local/file.txt ' , ' remote/path/hello-world.txt ' , false );
Observação
Uploads assíncronos são suportados com $client->uploadAsync()
. Ele retornará um GuzzleHttpPromisePromiseInterface
.
$ client -> download ( ' remote/path/hello-world.txt ' , ' /path/to/local/file.txt ' );
$ items = $ client -> listFiles ( ' remote/path/ ' );
Retorna uma matriz de objetos FileInfo.
$ item = $ client -> info ( ' remote/path/hello-world.txt ' );
Retorna uma instância de 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 );
A soma de verificação pode ser desabilitada usando o parâmetro $withChecksum
:
$ content = ' Hello, world! ' ;
$ client -> putContents ( ' hello-world.txt ' , $ content , false );
$ content = $ client -> getContents ( ' hello-world.txt ' );
echo $ content ; // Hello, world!