About This Sample
- Upload a file to Amazon S3 directly from a web-browser using an off-screen IFRAME generated by the Yahoo! User Interface Library so that the upload is handled in the background of the browser.
- Demonstrates the creation and signing of a POST policy statement in PHP.
- Demonstrates the use of the success_action_redirect form field to notify your server of a successful upload and allow your server to send a response to the client's browser.
Updates
[04.04.2009] Added an Amazon S3 POST policy class.
Prerequisites
- You must be signed up to use Amazon S3. You can sign up for Amazon S3 at http://aws.amazon.com/s3
- You need your AWS Access Key ID and Secret Access Key
- PHP 5 or greater
Running the Sample
- Open config.php
- Set the $AWSAccessKeyId variable to your AWS Access Key ID.
- Set the $AWSSecretKey variable to your AWS Secret Key.
- Set the $bucket variable to a bucket you own. If the bucket does not already exists, you will need to create it.
- Run sample.php or sample-attachments.php from a web-server.
Upload a file to Amazon S3 using a HTML Form POST:
- User clicks to submit a file to upload, and YUI creates an off-screen IFRAME to upload the file to Amazon S3.
- The file is sent via POST to Amazon S3 inside of the IFRAME.
- From within the IFRAME, Amazon S3 generates a redirect URL to the success_action_redirect url located on your server.
- The IFRAME makes a request to the redirect URL on your Webserver.
- Your Webserver returns data in JSON.
- The IFRAME sends JSON to the page.