Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.bunny.net/llms.txt

Use this file to discover all available pages before exploring further.

The official PHP SDK provides an easy way to interact with Bunny Storage in your PHP applications.

Installation

composer require bunnycdn/storage

Quickstart

Connect to your storage zone

use Bunny\Storage\Client;
use Bunny\Storage\Region;

$client = new Client(
    'your-access-key',
    'your-storage-zone-name',
    Region::FALKENSTEIN // Optional: storage zone region
);
Available regions:
Region ConstantCodeLocationCity
Region::FALKENSTEINdeFrankfurt, DEFalkenstein (default)
Region::LONDONukLondon, UKLondon
Region::STOCKHOLMseStockholm, SEStockholm
Region::NEW_YORKnyNew York, USNew York
Region::LOS_ANGELESlaLos Angeles, USLos Angeles
Region::SINGAPOREsgSingapore, SGSingapore
Region::SYDNEYsydSydney, AUSydney
Region::SAO_PAULObrSao Paulo, BRSao Paulo
Region::JOHANNESBURGjhJohannesburg, ZAJohannesburg

List files

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

// Navigate subdirectories
$subfolderFiles = $client->listFiles('my-folder/');
Returns an array of FileInfo objects. FileInfo properties:
  • getGuid() - Unique identifier
  • getName() - File name
  • getPath() - Directory path
  • getSize() - File size in bytes
  • getChecksum() - File checksum
  • getDateCreated() - Creation date
  • getDateModified() - Last modification date
  • isDirectory() - Whether it’s a directory

Upload a file

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

Upload multiple files

$files = glob('./uploads/*');

foreach ($files as $file) {
    if (is_file($file)) {
        $client->upload($file, 'batch/' . basename($file));
    }
}

Download a file

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

Get file info

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

echo $fileInfo->getName();
echo $fileInfo->getSize();
echo $fileInfo->getChecksum();

Check if file exists

if ($client->exists('remote/path/hello-world.txt')) {
    echo 'File exists!';
}

Delete a file

$client->delete('remote/path/hello-world.txt');

// Delete a directory
$client->delete('remote/path/folder/');

Delete multiple files

$errors = $client->deleteMultiple(['file1.txt', 'file2.txt', 'non-existing.txt']);

// Returns array of errors for failed deletions
// ['non-existing.txt' => 'Object not found']

Examples

Explore complete working examples in the GitHub repository:
ExampleDescription
file-uploadUpload a single file to storage
batch-uploadUpload multiple files sequentially
async-uploadUpload multiple files concurrently using promises
form-uploadHandle file uploads from HTML forms
list-filesList all files in a directory
download-fileDownload a file from storage
file-infoRetrieve file metadata
delete-fileDelete a single file
delete-multiple-filesDelete multiple files in one operation
delete-old-filesFind and delete files older than a specified age
kitchen-sinkComplete UI with upload, list, view, and delete

Resources