Installation guide

// Create a valid bucket and use a LocationConstraint
$result = $client->createBucket(array(
'Bucket' => $bucket,
'LocationConstraint' => \Aws\Common\Enum\Region::US_WEST_2
));
// Get the Location header of the response
echo $result['Location'] . "\n";
// Get the request ID
echo $result['RequestId'] . "\n";
You'll notice in the above example that we are using the Aws\Common\Enum\Region object to provide the
US_WEST_2 constant. The SDK provides various Enum classes under the Aws\Common\Enum namespace that can
be useful for remembering available values and ensuring you do not enter a typo.
Note
Using the enum classes is not required. You could just pass 'us-west-2' in the LocationConstraint key.
Waiting until the bucket exists
Now that we've created a bucket, let's force our application to wait until the bucket exists. This can be done easily
using a waiter. The following snippet of code will poll the bucket until it exists or the maximum number of polling
attempts are completed.
// Poll the bucket until it is accessible
$client->waitUntilBucketExists(array('Bucket' => $bucket));
Uploading objects
Now that you've created a bucket, let's put some data in it. The following example creates an object in your bucket
called data.txt that contains 'Hello!'.
// Upload an object to Amazon S3
$result = $client->putObject(array(
'Bucket' => $bucket,
'Key' => 'data.txt',
'Body' => 'Hello!'
));
// Access parts of the result object
echo $result['Expiration'] . "\n";
echo $result['ServerSideEncryption'] . "\n";
echo $result['ETag'] . "\n";
echo $result['VersionId'] . "\n";
echo $result['RequestId'] . "\n";
// Get the URL the object can be downloaded from
echo $result['ObjectURL'] . "\n";
The AWS SDK for PHP will attempt to automatically determine the most appropriate Content-Type header used to
store the object. If you are using a less common file extension and your Content-Type header is not added
automatically, you can add a Content-Type header by passing a ContentType option to the operation.
Uploading a file
The above example uploaded text data to your object. You can alternatively upload the contents of a file by passing
the SourceFile option. Let's also put some metadata on the object.
Amazon Simple Storage Service
103