Skip to content

Instantly share code, notes, and snippets.

@jonkiddy
Created July 11, 2015 18:40
Show Gist options
  • Select an option

  • Save jonkiddy/5401aef76338338ea3c4 to your computer and use it in GitHub Desktop.

Select an option

Save jonkiddy/5401aef76338338ea3c4 to your computer and use it in GitHub Desktop.
Some example of dealing with objects in S3 buckets.
// https://docs.aws.amazon.com/aws-sdk-php/guide/latest/service-s3.html#uploading-a-file
/**
* set key & secret
*/
$client = S3Client::factory(array(
'key' => ‘YOUR-KEY’,
'secret' => ‘YOUR-SECRET’
));
/**
* list buckets
*/
$result = $client->listBuckets();
/**
* create object
* contains link to the object
*/
$result = $client->putObject(array(
'Bucket' => 'temp-e-assign-upload-test',
'Key' => 'stuff/here/wee/data.txt',
'SourceFile' => $pathToFile,
'Metadata' => array(
'Foo' => 'abc',
'Baz' => '123'
)
));
/**
* wait until object exists
*/
$client->waitUntil('ObjectExists', array(
'Bucket' => 'temp-e-assign-upload-test',
'Key' => 'stuff/here/wee/data.txt'
));
/**
* list objects in bucket
*/
$result = $client->listObjects(array('Bucket' => 'temp-e-assign-upload-test'));
/**
* get meta data of an object
*/
$result = $client->headObject(['Bucket' => 'temp-e-assign-upload-test', 'Key' => 'data.txt'])->toArray();
$metadata = $result['Metadata'];
echo "<pre>";
print_r($result);
echo "</pre>";
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment