Skip to content

Instantly share code, notes, and snippets.

@cp6
Last active January 3, 2021 19:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cp6/cff63f23ec3727a7b306067780b5f2e0 to your computer and use it in GitHub Desktop.
Save cp6/cff63f23ec3727a7b306067780b5f2e0 to your computer and use it in GitHub Desktop.
Bunny CDN Storage API format
<?php
header("Content-type:application/json");
function storage($key, $dir = '')
{
return json_decode(file_get_contents("https://storage.bunnycdn.com/" . $dir . "/?AccessKey=" . $key . ""), true);
}
$array = storage('STORAGE-PASSWORD-HERE', 'STORAGENAME');
$items = array('data' => array());
foreach ($array as $value) {
$created = date('Y-m-d H:i:s', strtotime($value['DateCreated']));
$last_changed = date('Y-m-d H:i:s', strtotime($value['LastChanged']));
$name = $value['ObjectName'];
$guid = $value['Guid'];
if ($value['IsDirectory'] == true) {
$file_type = $size = $size_kb = $size_mb = $size_gb = null;
} else {
if (isset(pathinfo($value['ObjectName'])['extension'])) {
$file_type = pathinfo($value['ObjectName'])['extension'];
} else {
$file_type = null;
}
$size = $value['Length'];
$size_kb = floatval(($size / 1024));
$size_mb = floatval(($size / 1048576));
$size_gb = floatval(($size / 1073741824));
}
$items['data'][] = array('name' => $name, 'file_type' => $file_type, 'size' => $size, 'size_kb' => $size_kb,
'size_mb' => $size_mb, 'size_gb' => $size_gb, 'is_dir' => $value['IsDirectory'], 'created' => $created,
'last_changed' => $last_changed, 'guid' => $guid);
}
echo json_encode($items);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment