PhpRiot
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

Getting Information About Objects

To determine if a particular object exists in a bucket, use the isObjectAvailable() method. This method accepts as its only argument the object name (including the bucket name at the start).

You can also get information about a particular object using the getInfo() method. This also accepts the name of the object as its only argument. An array will be returned if the object exists, otherwise false is returned.

The following listing demonstrates the getInfo() method. In this listing we use getInfo() to find out more about the my-file.txt object we created earlier in this article.

Listing 8 Getting meta information about an object (get-info.php)
<?php
    require_once('Zend/Service/Amazon/S3.php');
 
    $awsKey       = '[your key]';
    $awsSecretKey = '[your secret key]';
 
    $bucketName = 'phpriot-test-bucket';
 
    $info = $s3->getInfo($bucketName . '/my-file.txt');
 
    if (!is_array($info)) {
        throw new Exception('Unable to retrieve info!');
    }
 
    var_dump($info);
?>
 
Output:
 
array
  'type' => string 'text/plain' (length=10)
  'size' => string '9' (length=1)
  'mtime' => int 1267746267
  'etag' => string '"bb6bc982bb3c1eedf3515edd9f802161"' (length=34)

In This Article



Bonus listings: 2 available