1. Go to this page and download the library: Download techyet/b2-sdk 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/ */
techyet / b2-sdk example snippets
use TechYet\B2\Client;
$client = new Client('accountId', 'applicationKey');
//Returns an array of Bucket objects indexed by the bucket name
$buckets = $client->listBuckets();
//Returns an array of File objects
$files = $buckets['testBucket']->listFileNames();
//Returns a File object
$file = $buckets['testBucket']->getFileByName('test.txt');
//Returns the file contents
$content = $file->download();
//Also returns the file contents
$content = $buckets['testBucket']->downloadFileByName('test.txt');
//Saves the file to disk and returns a success boolean
$success = $file->download([
'SaveAs' => '/path/to/save/location',
]);
//Also saves the file to disk and returns a success boolean
$file = $buckets['testBucket']->downloadFileByName('test.txt', [
'SaveAs' => '/path/to/save/location',
]);
//Returns a boolean value
$exists = $buckets['testBucket']->fileExists('test.txt');
//Returns a boolean value
$deleted = $buckets['testBucket']->getFileByName('test.txt')->delete();
//Returns a string containing the authorization token
$token = $buckets['testBucket']->getFileByName('test.txt')->getDownloadAuthorization([
'validDurationInSeconds' => 86400,
]);
//Returns a file object
$file = $buckets['testBucket']->uploadFile('test.txt.', 'This is a test');
//You can also pass a file resource
$file = $buckets['testBucket']->uploadFile('test.txt.', fopen('/path/to/input', 'r'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.