Skip to content

Instantly share code, notes, and snippets.

@chapdel
Forked from harshavardhana/aws-sdk-example.php
Created July 29, 2021 13:01
Show Gist options
  • Save chapdel/4a40308942d14695d7f827bac7f6f46f to your computer and use it in GitHub Desktop.
Save chapdel/4a40308942d14695d7f827bac7f6f46f to your computer and use it in GitHub Desktop.
AWS SDK PHP example with minio server
<?php
// Include the SDK using the Composer autoloader
date_default_timezone_set('America/Los_Angeles');
require 'vendor/autoload.php';
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'endpoint' => 'http://localhost:9000'
]);
$result = $s3->listBuckets();
echo "ListBuckets: \n";
foreach ($result['Buckets'] as $bucket) {
echo $bucket['Name'] . " " . $bucket['CreationDate'] . "\n";
}
echo "ListObjects: \n";
$results = $s3->getPaginator('ListObjects', [
'Bucket' => 'testbucket'
]);
foreach ($results as $result) {
foreach ($result['Contents'] as $object) {
echo $object['Key'] . " " . $object['Size'] . "\n";
}
}
echo "ListObjects: delimited\n";
$results = $s3->getPaginator('ListObjects', [
'Bucket' => 'testbucket',
'Delimiter' => '/'
]);
$expression = '[CommonPrefixes[].Prefix, Contents[].Key][]';
foreach ($results->search($expression) as $item) {
echo $item . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment