使用Zend Framework列出S3目录中的所有文件

时间:2011-11-06 22:18:54

标签: php zend-framework amazon-s3

如何列出PHP中Bucket的Amazon S3目录中的所有文件(也许还有Zend Framework的帮助程序)?

1 个答案:

答案 0 :(得分:1)

参见示例#5:

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

  

getObjectsByBucket($ 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";
}

<强>更新

亚马逊s3中的“文件夹”是前缀,你可以设置一个参数:

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.

参见S3.php的第293行