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

Using Objects Stored in Amazon S3 Buckets

Finally, let's look at how other users can access files you store in your Amazon S3 buckets. The name of the bucket maps directly to the following domain name to the following web addresses:

  • http://[bucketName].s3.amazonaws.com/[objectName]
  • http://s3.amazonaws.com/[bucketName]/[objectName]

Using our previous examples from this article, you can access the my-file.txt file at the following URLs:

  • http://phpriot-test-bucket.s3.amazonaws.com/my-file.txt
  • http://s3.amazonaws.com/phpriot-test-bucket/my-file.txt

If we didn't set the permissions to be publicly readable, then it would not be possible for others to access your files.

You can now link to these files directly from your web pages, rather than hosting your files yourself. The following listing demonstrates how you might achieve this. It uses Amazon S3 for CSS, images, and for a file download link.

Listing 12 Using your Amazon S3 bucket on your web site (use-cdn.php)
<?php
    $bucketName = 'my-company-bucket';
    $cdnUrl = 'http://' . $bucketName . '.s3.amazonaws.com';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Sample Amazon S3 CDN Usage Page</title>
        <link rel="stylesheet"
              href="<?php echo $cdnUrl ?>/css/styles.css"
              type="text/css"
              media="all" />
    </head>
    <body>
        <div>
            <img src="<?php echo $cdnUrl ?>/images/logo.png" alt="My Logo" />
        </div>
        <div>
            <a href="<?php echo $cdnUrl ?>/assets/profile.pdf">
                Download company profile
            </a>
        </div>
    </body>
</html>

In This Article



Bonus listings: 2 available