BunnyCDN.PHP.Storage
3.4.0
La bibliothèque PHP officielle utilisée pour interagir avec l'API BunnyCDN Storage.
composer require bunnycdn/storage
Créez une instance de BunnyStorageClient
avec les détails d'authentification
$ client = new Bunny Storage Client ( ' access-key ' , ' storage-zone ' , Bunny Storage Region :: SINGAPORE );
Le constructeur BunnyCDNStorage prend les paramètres suivants :
$ client -> upload ( ' /path/to/local/file.txt ' , ' remote/path/hello-world.txt ' );
La somme de contrôle peut être désactivée à l'aide du paramètre $withChecksum
:
$ client -> upload ( ' /path/to/local/file.txt ' , ' remote/path/hello-world.txt ' , false );
Note
Les téléchargements asynchrones sont pris en charge avec $client->uploadAsync()
. Il renverra un GuzzleHttpPromisePromiseInterface
.
$ client -> download ( ' remote/path/hello-world.txt ' , ' /path/to/local/file.txt ' );
$ items = $ client -> listFiles ( ' remote/path/ ' );
Renvoie un tableau d'objets FileInfo.
$ item = $ client -> info ( ' remote/path/hello-world.txt ' );
Renvoie une instance 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 );
La somme de contrôle peut être désactivée à l'aide du paramètre $withChecksum
:
$ content = ' Hello, world! ' ;
$ client -> putContents ( ' hello-world.txt ' , $ content , false );
$ content = $ client -> getContents ( ' hello-world.txt ' );
echo $ content ; // Hello, world!