PHP code example of steppinghat / backblaze-b2-bundle

1. Go to this page and download the library: Download steppinghat/backblaze-b2-bundle 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/ */

    

steppinghat / backblaze-b2-bundle example snippets




return [
    // ...
    SteppingHat\BackblazeB2\BackblazeB2Bundle::class => ['all' => true]
]



use SteppingHat\BackblazeB2\Client\BackblazeClient;

class ExampleService {

    protected BackblazeClient $client;

    public function __construct(BackblazeClient $client) {
        $this->client = $client;    
    }
    
}

$bucket = $client->createBucket('bucketName', Bucket::TYPE_PRIVATE);

$buckets = $client->listBuckets();

$bucket = $client->updateBucket($bucket, Bucket::TYPE_PUBLIC);

$client->deleteBucket($bucket);

// List all files across all buckets
$files = $client->listFiles();

// List all files in a specific bucket
$files = $client->listFiles($bucket);

// Search for a specific file
$files = $client->listFiles($bucket, 'animals/dogs/floof.png');

// Search for all files matching a prefix
$files = $client->listFiles($bucket, null, 'animals/dogs/');

if($client->fileExists($bucket, 'animals/dogs/doggo.jpg')) {
    // ...
}

$file = $client->getFileInfo($file);
// or
$file = $client->getFileInfoById($fileId);

$client->deleteFile($file);

$client->deleteFile($file, true);

$fileContent = 'Hello world!';
// or
$fileContent = file_get_contents('hello.txt');
$client->upload($bucket, $fileContent, 'files/hello.txt');

$file = fopen('smoldoggo.png', 'r');
$client->upload($bucket, $file, 'animals/dogs/smoldoggo.png');

$content = $client->download($file);
echo $file;
// Hello world!

$resource = fwrite('/tmp/smoldoggo.png', 'w');
$client->download($file, $resource);
fclose($resource);