PHP code example of bunnycdn / storage

1. Go to this page and download the library: Download bunnycdn/storage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bunnycdn / storage example snippets


$client = new \Bunny\Storage\Client('access-key', 'storage-zone', \Bunny\Storage\Region::SINGAPORE);

$client->upload('/path/to/local/file.txt', 'remote/path/hello-world.txt');

$client->upload('/path/to/local/file.txt', 'remote/path/hello-world.txt', false);

$client->download('remote/path/hello-world.txt', '/path/to/local/file.txt');

$items = $client->listFiles('remote/path/');

$item = $client->info('remote/path/hello-world.txt');

$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);

$content = 'Hello, world!';
$client->putContents('hello-world.txt', $content, false);

$content = $client->getContents('hello-world.txt');
echo $content; // Hello, world!