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

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)
    $awsKey       = '[your key]';
    $awsSecretKey = '[your secret key]';
    $s3 = new Zend_Service_Amazon_S3($awsKey, $awsSecretKey);
  0 => string 'phpriot-test-bucket' (length=19)

In This Article

Bonus listings: 2 available