Path: blob/master/code_examples/php_examples/S3examples/s3-request-aws.php
4084 views
<?php1// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.2// SPDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-s3-developer-guide/blob/master/LICENSE-SAMPLECODE )34require 'vendor/autoload.php';56use Aws\Sts\StsClient;7use Aws\S3\S3Client;8use Aws\S3\Exception\S3Exception;910$bucket = '*** Your Bucket Name ***';1112$s3 = new S3Client([13'region' => 'us-east-1',14'version' => 'latest',15]);1617// Retrieve the list of buckets.18$result = $s3->listBuckets();1920try {21// Retrieve a paginator for listing objects.22$objects = $s3->getPaginator('ListObjects', [23'Bucket' => $bucket24]);2526echo "Keys retrieved!" . PHP_EOL;2728// Print the list of objects to the page.29foreach ($objects as $object) {30echo $object['Key'] . PHP_EOL;31}32} catch (S3Exception $e) {33echo $e->getMessage() . PHP_EOL;34}353637