The most comprehensive, feature packed and easy to use PHP class for the BunnyCDN pull, video streaming and storage zones API.
This class whilst having a main focus on storage zone interaction includes pull zone features. Combining API with FTP, managing and using BunnyCDN storage zones just got easier.
Note video streaming API is seemingly not finalized and is changing
For Pull zone, billing and statistics API interaction you will need your BunnyCDN API key, this is found in your dashboard in the My Account section.
If you want to interact with storage zones you will need your BunnyCDN API key set and the name of the storage zone.
listStorageZones()
returns all the storage zone data/info for the account.
- List storage zones
- Add/create storage zone
- Delete storage zone
- Create folder in storage zone
- Delete folder in storage zone
- Delete file in storage zone
- Delete all files in a folder in storage zone
- Download a file from storage zone
- Download a file from storage zone with progress percentage
- Download all files in a folder from storage zone
- Upload file to storage zone
- Upload file to storage zone with progress percentage
- Upload all files in a folder to storage zone
- Rename file or folder in storage zone
- Move file in storage zone
- Get file size in storage zone
- Get directory size in storage zone
- Navigate/List directories in storage zone
- List all from storage zone directory
- List all files formatted from storage zone directory
- List all folders formatted from storage zone directory
- List all formatted from storage zone directory
- Get usage statistics
- Get billing data
- View balance
- View monthly charge
- View monthly charge breakdown
- Apply coupon code
- List pull zones
- Get pull zone
- Add pull zone
- Update pull zone
- Delete pull zone
- Purge pull zone
- Add hostname to pull zone
- Remove hostname from pull zone
- Set force SSL for pull zone
- List pull zone HTTP access logs
- Calculate costs
Usage is simple, install with:
composer require corbpie/bunny-cdn-api
Use like:
require __DIR__ . '/vendor/autoload.php';
use Corbpie\BunnyCdn\BunnyAPI;
$bunny = new bunnyAPI();//Initiate the class
echo $bunny->listPullZones();
option 1 (preferred)
Line 12 bunnyAPI.php
const API_KEY = 'XXXX-XXXX-XXXX';
option 2
With apiKey()
(needs setting with each calling of class)
$bunny->apiKey('XXXX-XXXX-XXXX');//Bunny api key
To have max execution time of 300 seconds
$bunny = new bunnyAPI(300);
Storage zone name and access key for storage zone interaction (not needed if just using pull zone functions)
Set $access_key = ''
to obtain key automatically (storage name must be accurate)
$bunny->zoneConnect($storagename, $access_key);
$storagename
name of storage zone string
$access_key
key/password to storage zone string
optional
List storage zones
$bunny->listStorageZones();
returns array
Add a storage zone
$bunny->addStorageZone($newstoragezone);
$newstoragezone
name of storage zone to create string
Delete a storage zone
$bunny->deleteStorageZone($id);
$id
id of storage zone to delete int
Get directory size
$bunny->dirSize($dir);
$dir
directory to get size of string
Return current directory
$bunny->currentDir();
returns string
Change directory
$bunny->changeDir($dir);
$dir
directory navigation (FTP rules) string
Move to parent directory
$bunny->moveUpOne();
Create folder in current directory
$bunny->createFolder($newfolder);
$newfolder
Create a folder in current directory string
Delete folder
$bunny->deleteFolder($name);
$name
Name of folder to delete (must be empty) string
Delete a file
$bunny->deleteFile($name);
$name
Name of file to delete string
Delete all files in a folder
$bunny->deleteAllFiles($dir);
$dir
Directory to delete all files in string
Rename a file
BunnyCDN does not allow for ftp_rename so file copied to new name and then old file deleted.
$bunny->renameFile($directory, $old_file_name, $new_file_name);
$directory
Directory that contains the file string
$old_name
Object that is being renamed string
$new_name
New name for object string
Move a file
$bunny->moveFile($file, $move_to);
$file
File to move string
$move_to
Directory to move file to string
Download a file
$bunny->downloadFile($save_as, $get_file, $mode);
$save_as
Save file as string
$get_file
File to download string
$mode
FTP mode to use INT
Download all files in a directory
$bunny->downloadAll($dir_dl_from, $dl_into, $mode);
$dir_dl_from
Directory to download all from string
$dl_into
Download into string
$mode
FTP mode to use INT
Upload a file
$bunny->uploadFile($upload, $upload_as, $mode);
$upload
File to upload string
$upload_as
Upload as string
$mode
FTP mode to use INT
Upload all files from a local folder
$bunny->uploadAllFiles($dir, $place, $mode);
$dir
Upload all files from this directory string
$place
Upload to string
$mode
FTP mode to use INT
Return storage zone files and folder data (Original)
$bunny->listAllOG();
returns array
Return storage zone directory files formatted
$bunny->listFiles($location);
$location
Directory to get and return data string
returns array
Return storage zone directory folders formatted
$bunny->listFolders($location);
$location
Directory to get and return data string
returns array
Return storage zone directory file and folders formatted
$bunny->listAll($location);
$location
Directory to get and return data string
returns array
List all pull zones and data
$bunny->listPullZones();
returns array
List pull zones data for id
$bunny->pullZoneData($id);
$id
Pull zone to get data from int
returns array
Purge pull zone data
$bunny->purgePullZone($id);
$id
Pull zone to purge int
Delete pull zone data
$bunny->deletePullZone($id);
$id
Pull zone to delete int
Lists pullzone hostnames and amount
$bunny->pullZoneHostnames($pullzone_id);
Add hostname to pull zone
$bunny->addHostnamePullZone($id, $hostname);
$id
Pull zone hostname will be added to int
$hostname
Hostname to add string
Remove a hostname from pull zone
$bunny->removeHostnamePullZone($id, $hostname);
$id
Pull zone hostname be removed from int
$hostname
Hostname to remove string
Change force SSL status for pull zone
$bunny->forceSSLPullZone($id, $hostname, $force_ssl);
$id
Pull zone hostname change status int
$hostname
Affected hostname string
$force_ssl
True = on, FALSE = off bool
Add ip to block for pullzone
$bunny->addBlockedIpPullZone($pullzone_id, $ip, $db_log = false);
Un block an ip for pullzone
$bunny->unBlockedIpPullZone($pullzone_id, $ip, $db_log = false);
List all blocked ip's for pullzone
$bunny->listBlockedIpPullZone($pullzone_id);
Purge cache for a URL
$bunny->purgeCache($url);
$url
Purge cache for this url string
Pull zone logs as formatted array
$bunny->pullZoneLogs($id, $date);
$id
Pull zone id int
$date
Date for logs, only past 3 days (mm-dd-yy) string
Get usage statistics
$bunny->getStatistics();
returns array
Get billing data
$bunny->getBilling();
returns array
Get account balance
$bunny->balance();
returns float
Get monthly charge
$bunny->monthCharges();
returns float
Get monthly charge breakdown for region
$bunny->monthChargeBreakdown();
returns array
Lists total billing amount and first date time
$bunny->totalBillingAmount();
returns array
Apply a coupon code
$bunny->applyCoupon($code);
Set Json header
$bunny->jsonHeader();
Convert/format bytes to other data types
$bunny->convertBytes($bytes, $convert_to = 'GB', $format = true, $decimals = 2);
Convert bool to int value
$bunny->boolToInt($bool);
returns int
Close connection (Optional)
$bunny->closeConnection();
Set video stream library id
$bunny->setStreamLibraryId($library_id);
$library_id
stream library id int
Set video collection guid
$bunny->setStreamCollectionGuid($collection_guid);
$collection_guid
video collection guid string
Set video guid
$bunny->setStreamVideoGuid($video_guid);
$video_guid
video guid string
Get video collections for library
$bunny->getStreamCollections($library_id, $page, $items_pp,$order_by);
$library_id
library id int
0 = use set library id from setStreamLibraryId()
$page
page number int
$items_pp
items to show int
$order_by
order by string
Get streams for a collection
$bunny->getStreamForCollection($library_id, $collection_guid);
$library_id
library id int
0 = use set library id from setStreamLibraryId()
$collection_guid
video collection guid string
leave empty to use set collection guid from setStreamCollectionGuid()
Update stream collection
$bunny->updateCollection($library_id, $collection_guid);
$library_id
library id int
$collection_guid
video collection guid string
Delete stream collection
$bunny->deleteCollection($library_id, $collection_guid);
$library_id
library id int
$collection_guid
video collection guid string
Create stream collection
$bunny->createCollection($library_id, $collection_guid);
$library_id
library id int
$collection_guid
video collection guid string
List videos for library
$bunny->listVideos($library_id, $collection_guid);
$library_id
library id int
$collection_guid
video collection guid string
Get video information
$bunny->getVideo($library_id, $collection_guid);
$library_id
library id int
$collection_guid
video collection guid string
Delete video
$bunny->deleteVideo($library_id, $collection_guid);
$library_id
library id int
$collection_guid
video collection guid string
Create video
$bunny->createVideo($library_id, $video_title, $collection_guid);
$library_id
library id int
$video_title
video title string
$collection_guid
video collection guid string
Upload video
Need to use createVideo() first to get video guid
$bunny->uploadVideo($library_id, $collection_guid, $video_to_upload);
$library_id
library id int
$collection_guid
video collection guid string
$video_to_upload
video file string
Set thumbnail for video
$bunny->setThumbnail($library_id, $video_guid, $thumbnail_url);
$library_id
library id int
$video_guid
video guid string
$thumbnail_url
image url string
Add captions
$bunny->addCaptions($library_id, $video_guid, $collection_guid, $label, $captions_file);
$library_id
library id int
$video_guid
video guid string
$srclang
caption srclang string
$label
label for captions string
$captions_file
caption file URL string
Delete captions
$bunny->deleteCaptions($library_id, $video_guid, $srclang);
$library_id
library id int
$video_guid
video guid string
$srclang
captions srclang string
- Proper exception handling