Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

php - List all Files in a S3 Directory with Zend Framework

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:
";
  $data = $s3->getObject("my-own-bucket/$name");
  echo "with data: $data
";
}

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...