Amazon S3 Sample in PHP

Sample Code & Libraries>Amazon S3 Sample in PHP
Community Contributed Software

  • Amazon Web Services provides links to these packages as a convenience for our customers, but software not authored by an "@AWS" account has not been reviewed or screened by AWS.
  • Please review this software to ensure it meets your needs before using it.

A basic PHP file that interacts with Amazon S3 to demonstrate basic PUT, GET, and DELETE operations.

Details

Submitted By: EricW@AWS
AWS Products Used: Amazon S3
Language(s): PHP
License: New BSD
Created On: March 13, 2006 5:15 PM GMT
Last Updated: September 21, 2008 9:15 PM GMT
Download

About This Sample

  • A basic PHP file that interacts with Amazon S3 to demonstrate basic PUT, GET, and DELETE operations.
  • Be sure to run this program on a secure server owned by you, as it passes the Secret Access Key as a query string parameter.
  • See the README file in the download for more information.

What's New

  • 2007-12-03: Updated date format string for php5 compatibility

Prerequisites

  • You must be signed up to use Amazon S3. You can sign up for Amazon S3 at http://aws.amazon.com/s3.
  • This sample was built and tested using PHP 5.
  • Requires the following modules:
    • Crypt_HMAC
    • HTTP_Request

Running the Sample

  1. Add the s3.php file to your web server that supports PHP.
  2. Open a browser and view the file.

Comments

Unable to run the sample
I am unable to run the sample PHP code. I get the below error. believe the crypt/HMAC is deprecated and the new one is Crypt/HMAC2. I did install the package, but it still gives the same error. Running php 5.2.9: Warning: require_once(Crypt/HMAC.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\s3.php on line 32 Fatal error: require_once() [function.require]: Failed opening required 'Crypt/HMAC.php' (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\s3.php on line 32
seveorkay on October 6, 2009 5:29 AM GMT
1 bug that ruins GETs!
Folks - i spent days on this and other code examples. This is the one to use, but there's a bug that will kill the GET and drive you nuts! Add this line: if ($verb != "PUT") $contentType=""; before you assemble the $stringToSign string. $stringToSign = "$verb\n\n$contentType\n$httpDate\nx-amz-acl:$acl\n/$resource"; BTW: PHP4 users - this will work for you too! You're welcome! ;)
addictech on November 22, 2008 1:13 AM GMT
Ok, but needs to be updated.
Looks pretty good, but it definitely needs some updating and cleaning up. Worst thing is that this script still uses $_REQUEST, which needs to be either GET or POST. Otherwise, it should do the trick.
johndubya28 on November 21, 2008 11:10 PM GMT
s3.class.php to support <LocationConstraint>EU</LocationConstraint>
hello! did you already modify s3.class.php to support the EU. have a look at this: http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTBucketPUT.html would be cool to set this parameter using s3.class.php. can you help? greetings t.
thommyfilm on January 8, 2008 2:07 PM GMT
Looks simple, but..
Looks simple, but I'm stuck on super beginner stuff. I get the error "AWS authentication requires a valid Date or x-amz-date header"
Darrell Silver on November 30, 2007 5:07 AM GMT
We are temporarily not accepting new comments.
©2014, Amazon Web Services, Inc. or its affiliates. All rights reserved.