Reputation: 15
I'm attempting to list the files in my S3 bucket but I keep getting a PHP Error when running this code:
require_once './S3.php';
define('awsAccessKey', 'xxx');
define('awsSecretKey', 'xxx');
$s3 = new S3(awsAccessKey, awsSecretKey);
$objects = $s3->list_objects("BUCKETNAME",array("max-keys"=>5));
foreach ($objects->body->Contents as $item){
print_r($item->Key."");
}
I get:
PHP Fatal error: Call to undefined method S3::list_objects()
Google isn't helping me. I can put files in my bucket but I can't list them. Any ideas?
Upvotes: 0
Views: 1366
Reputation: 919
Am using this library https://github.com/aws/aws-sdk-php. A properly maintained source.
The function you are looking for can be called as S3->listObjects()
using this library
Upvotes: 0
Reputation: 6945
Well, the obvious answer is that the (third-party; not from Amazon) S3
class doesn't have a list_objects()
method.
This class does, however, have a getBucket()
method that probably does the same thing.
If you meant to use the official AWS SDK for PHP 1.x, you'd look at the AmazonS3::list_objects()
method.
If you want to use something current and supported (i.e., AWS SDK for PHP 2.x), you'd look at the S3Client::listObjects()
method.
Upvotes: 1