Created
January 29, 2019 08:13
-
-
Save minedun6/80f5c637c25e51888b5a9c1fc51ff63c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
's3-backups' => [ | |
'driver' => 's3', | |
'key' => config('aws.public_key'), | |
'secret' => config('aws.secret_key'), | |
'region' => config('aws.region'), | |
'bucket' => $bucket_name | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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