Last active
December 14, 2015 08:09
-
-
Save wschwarz/5055526 to your computer and use it in GitHub Desktop.
Simple s3 list buckets script using phpsdk v2
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 | |
require 'vendor/autoload.php'; | |
use Aws\Common\Aws; | |
use Aws\S3\Exception\S3Exception; | |
$aws = Aws::factory('/path/config.php'); | |
$s3v2 = $aws->get('s3'); | |
echo "ListBuckets with SDK Version 2:\n"; | |
echo "------------------------\n"; | |
try { | |
$result = $s3v2->listBuckets(); | |
foreach ($result['Buckets'] as $bucket) { | |
echo "- {$bucket['Name']}\n"; | |
listImagesByBucket($s3v2, $bucket['Name']); | |
} | |
} catch (Aws\S3\Exception\S3Exception $e) { | |
echo "Request failed.\n"; | |
} | |
echo "\n"; | |
function listImagesByBucket($s3ref, $bucketName) { | |
try { | |
$result = $s3ref->listObjects(array( | |
'Bucket' => $bucketName, | |
)); | |
// Loop through and display the part numbers | |
foreach ($result['Contents'] as $image) { | |
echo "{$image['Key']}\n"; | |
} | |
} catch (S3Exception $e) { | |
echo "Error during S3 ListObjects operation.\n"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment