PhpRiot
Follow phpriot on Twitter
Sponsored Link
Download Article
Download this article or the entire “Zend Framework 101” series with all listings and files.

Includes 2 bonus listings!




More information
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

Related Books
PHP Solutions: Dynamic Web Design Made Easy

PHP Solutions: Dynamic Web Design Made Easy

This is the second edition of David Power's highly-respected PHP Solutions: Dynamic Web Design...

Cloud Computing Bible

Cloud Computing Bible

The complete reference guide to the hot technology of cloud computing Its potential for...

Zend Framework 101: Zend_Service_Amazon_S3

Managing Buckets

The operations you can perform on a bucket are as follows:

  • Retrieve a list of buckets
  • Create a new bucket
  • Clear all objects from a bucket
  • Remove a bucket

There are strict limitations on the name of buckets. The names can not be more than 255 characters, and contain only lower-case letters, numbers, underscores, periods and dashes.

Bucket names are used to create a unique domain name by which you can access objects in the bucket. Accessing your files is covered later in this article.

Caution: Bucket names are publicly visible in any URL you use to link to files in your buckets. As such, ensure the names are appropriate for their purpose.

Once you have created a bucket, all subsequent operations on the bucket (including managing objects in the bucket) require the bucket name.

Retrieve a List of Buckets

You can retrieve a list of existing buckets using the getBuckets() method. This returns an array, with each entry being the name of the bucket. The following code demonstrates this.

Listing 3 Retrieving a list of buckets (list-buckets.php)
<?php
    require_once('Zend/Service/Amazon/S3.php');
 
    $awsKey       = '[your key]';
    $awsSecretKey = '[your secret key]';
 
    $s3 = new Zend_Service_Amazon_S3($awsKey, $awsSecretKey);
 
    var_dump($s3->getBuckets());
?>
 
Output:
 
array
  0 => string 'phpriot-test-bucket' (length=19)

In This Article



Bonus listings: 2 available