-1

How I can list all files in an Amazon S3 Directory of a Bucket in PHP (and maybe with a helper from Zend Framework)?

Maxim Zubarev
  • 2,403
  • 2
  • 29
  • 48

1 Answers1

1

See example #5:

http://framework.zend.com/manual/en/zend.service.amazon.s3.html

getObjectsByBucket($bucket) returns the list of the object keys, contained in the bucket.

$s3 = new Zend_Service_Amazon_S3($my_aws_key, $my_aws_secret_key);

$list = $s3->getObjectsByBucket("my-own-bucket");
foreach($list as $name) {
  echo "I have $name key:\n";
  $data = $s3->getObject("my-own-bucket/$name");
  echo "with data: $data\n";
}

Update:

"Folders" in amazon s3 are prefixes, you can set a param:

prefix - Limits the response to keys which begin with the indicated prefix. You can use prefixes to separate a bucket into different sets of keys in a way similar to how a file system uses folders.

See line #293 of S3.php

Ashley
  • 5,939
  • 9
  • 39
  • 82
  • i did see this but if i got some thousands directories in a bucket it is somehow pretty bad for the performance to go through really _each_ directory. I want already have something like s3->listFiles('my-own-bucket/directory1/directory2'); – Maxim Zubarev Nov 06 '11 at 22:32
  • @dotwired you can set which folder to get by using the params, see updated answer – Ashley Nov 07 '11 at 09:24