Installation guide

// Upload an object by streaming the contents of a file
// $pathToFile should be absolute path to a file on disk
$result = $client->putObject(array(
'Bucket' => $bucket,
'Key' => 'data_from_file.txt',
'SourceFile' => $pathToFile,
'Metadata' => array(
'Foo' => 'abc',
'Baz' => '123'
)
));
// We can poll the object until it is accessible
$client->waitUntilObjectExists(array(
'Bucket' => $this->bucket,
'Key' => 'data_from_file.txt'
));
Uploading from a stream
Alternatively, you can pass a resource returned from an fopen call to the Body parameter.
// Upload an object by streaming the contents of a PHP stream.
// Note: You must supply a "ContentLength" parameter to an
// operation if the steam does not respond to fstat() or if the
// fstat() of stream does not provide a valid the 'size' attribute.
// For example, the "http" stream wrapper will require a ContentLength
// parameter because it does not respond to fstat().
$client->putObject(array(
'Bucket' => $bucket,
'Key' => 'data_from_stream.txt',
'Body' => fopen($pathToFile, 'r+')
));
Because the AWS SDK for PHP is built around Guzzle, you can also pass an EntityBody object.
// Be sure to add a use statement at the beginning of you script:
// use Guzzle\Http\EntityBody;
// Upload an object by streaming the contents of an EntityBody object
$client->putObject(array(
'Bucket' => $bucket,
'Key' => 'data_from_entity_body.txt',
'Body' => EntityBody::factory(fopen($pathToFile, 'r+'))
));
Listing your buckets
You can list all of the buckets owned by your account using the listBuckets method.
$result = $client->listBuckets();
foreach ($result['Buckets'] as $bucket) {
// Each Bucket value will contain a Name and CreationDate
echo "{$bucket['Name']} - {$bucket['CreationDate']}\n";
}
All service operation calls using the AWS SDK for PHP return a Guzzle\Service\Resource\Model object. This
object contains all of the data returned from the service in a normalized array like object. The object also contains a
get() method used to retrieve values from the model by name, and a getPath() method that can be used to
retrieve nested values.
Amazon Simple Storage Service
104