Categories
Servers

Uploading to AWS S3

101 Demo

[code]
<?php
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
‘version’ => ‘latest’,
‘region’ => ‘ap-southeast-2’,  //Sydney
‘scheme’ => ‘http’, //omit, or https on servers that support it
‘credentials’ => [
‘key’ => ‘ YOUR KEY ‘,
‘secret’ => ‘ YOUR SECRET ‘
]
]);

// Upload a publicly accessible file. The file size and type are determined by the SDK.
try {
$s3->putObject([
‘Bucket’ => ‘yourbucket’,
‘Key’ => ‘path/to/key.png’,
‘Body’ => fopen(‘my-picture.png’, ‘r’),
‘ACL’ => ‘public-read’,
]);

echo "<p>Picture uploaded [tick]</p>";

} catch (Aws\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n";
}
?>

[/code]