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)
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)
No comments:
Post a Comment