BunnyCDN.PHP.Storage
3.4.0
The official PHP library used for interacting with the BunnyCDN Storage API.
composer require bunnycdn/storage
Create an instance of the BunnyStorageClient
with the authentication details
$client = new BunnyStorageClient('access-key', 'storage-zone', BunnyStorageRegion::SINGAPORE);
The BunnyCDNStorage constructor takes the following parameters:
$client->upload('/path/to/local/file.txt', 'remote/path/hello-world.txt');
The checksum can be disabled using the $withChecksum
parameter:
$client->upload('/path/to/local/file.txt', 'remote/path/hello-world.txt', false);
Note
Async uploads are supported with $client->uploadAsync()
. It will return a GuzzleHttpPromisePromiseInterface
.
$client->download('remote/path/hello-world.txt', '/path/to/local/file.txt');
$items = $client->listFiles('remote/path/');
Returns an array of FileInfo objects.
$item = $client->info('remote/path/hello-world.txt');
Returns an instance of 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);
The checksum can be disabled using the $withChecksum
parameter:
$content = 'Hello, world!';
$client->putContents('hello-world.txt', $content, false);
$content = $client->getContents('hello-world.txt');
echo $content; // Hello, world!