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

Object operations

The object is the basic storage unit in S3. Object stores unstructured data, which can be any size up to 4 gigabytes. There's no limit on how many objects can be stored on the system.

The object are contained in buckets. Object is identified by name, which can be any utf-8 string. It is common to use hierarchical names (such as Pictures/Myself/CodingInPHP.jpg) to organise object names. Object name is prefixed with bucket name when using object functions, so for object "mydata" in bucket "my-own-bucket" the name would be my-own-bucket/mydata.

Objects can be replaced (by rewriting new data with the same key) or deleted, but not modified, appended, etc. Object is always stored whole.

By default, all objects are private and can be accessed only by their owner. However, it is possible to specify object with public access, in which case it will be available through the URL:[bucket-name]/[object-name].

  • putObject($object, $data, $meta) created an object with name $object (should contain the bucket name as prefix!) having $data as its content.

    Optional $meta parameter is the array of metadata, which currently supports the following parameters as keys:


    MIME content type of the data. If not specified, the type will be guessed according to the file extension of the object name.


    The access to the item. Following access constants can be used:


    Only the owner has access to the item.


    Anybody can read the object, but only owner can write. This is setting may be used to store publicly accessible content.


    Anybody can read or write the object. This policy is rarely useful.


    Only the owner has write access to the item, and other authenticated S3 users have read access. This is useful for sharing data between S3 accounts without exposing them to the public.

    By default, all the items are private.

    Example 772. Zend_Service_Amazon_S3 Public Object Example

    require_once 'Zend/Service/Amazon/S3.php';

    $s3 = new Zend_Service_Amazon_S3($my_aws_key$my_aws_secret_key);

    Zend_Service_Amazon_S3::S3_ACL_HEADER =>
    // or:
    Zend_Service_Amazon_S3::S3_ACL_HEADER =>
    "Go to to see me!\n";

  • getObject($object) retrieves object data from the storage by name.

  • removeObject($object) removes the object from the storage.

  • getInfo($object) retrieves the metadata information about the object. The function will return array with metadata information. Some of the useful keys are:


    The MIME type of the item.


    The size of the object data.


    UNIX-type timestamp of the last modification for the object.


    The ETag of the data, which is the MD5 hash of the data, surrounded by quotes (").

    The function will return FALSE if the key does not correspond to any existing object.

  • getObjectsByBucket($bucket) returns the list of the object keys, contained in the bucket.

    Example 773. Zend_Service_Amazon_S3 Object Listing Example

    require_once 'Zend/Service/Amazon/S3.php';

    $s3 = new Zend_Service_Amazon_S3($my_aws_key$my_aws_secret_key);

    $list $s3->getObjectsByBucket("my-own-bucket");
    $list as $name) {
    "I have $name key:\n";
    $data $s3->getObject("my-own-bucket/$name");
    "with data: $data\n";

  • isObjectAvailable($object) checks if the object with given name exists.

  • putFile($path, $object, $meta) puts the content of the file in $path into the object named $object.

    The optional $meta argument is the same as for putObject. If the content type is omitted, it will be guessed basing on the source file name.

Zend Framework