Zend Framework 101: Zend_Service_Amazon_S3
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.
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.
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)