Skip to content

Instantly share code, notes, and snippets.

@minedun6
Created January 29, 2019 08:13
Show Gist options
  • Save minedun6/80f5c637c25e51888b5a9c1fc51ff63c to your computer and use it in GitHub Desktop.
Save minedun6/80f5c637c25e51888b5a9c1fc51ff63c to your computer and use it in GitHub Desktop.
<?php
's3-backups' => [
'driver' => 's3',
'key' => config('aws.public_key'),
'secret' => config('aws.secret_key'),
'region' => config('aws.region'),
'bucket' => $bucket_name
]
<?php
function MakeReadable($bytes) {
if ($bytes > 0) {
$i = floor(log($bytes, 1024));
return round($bytes / pow(1024, $i), [0,0,2,2,3][$i]).['B','kB','MB','GB','TB'][$i];
}
return $bytes;
}
<?php
$disk = Storage::disk('s3-backups');
$backups = collect($disk->files($bucketPath))->sortByDesc(function ($file) use ($disk) {
return $disk->lastModified($file);
})->map(function ($backup) use ($disk) {
return [
'url' => $disk->url($backup),
'size' => MakeReadable($disk->size($backup)),
'mimeType' => $disk->mimeType($backup),
'lastModified' => date('Y-m-d H:i:s', $disk->lastModified($backup))
];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment