-
-
Save ricardofriba/2ae9a7b55a1fff83dc6f7a30419714da to your computer and use it in GitHub Desktop.
Amazon AWS PHP 2 SDK S3 Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://www.leofs.org/docs/s3_client.html | |
// i used composer with the following composer.json file and then called composer install | |
// {"require":{"aws/aws-sdk-php": "2.*"}} | |
require "vendor/autoload.php"; | |
use Aws\Common\Enum\Region; | |
use Aws\S3\S3Client; | |
$client = S3Client::factory(array( | |
"key" => "YOUR ACCESS KEY ID", | |
"secret" => "YOUR SECRET ACCESS KEY", | |
"region" => Region::US_EAST_1, | |
"scheme" => "http", | |
)); | |
// list buckets | |
$buckets = $client->listBuckets()->toArray(); | |
foreach($buckets as $bucket){ | |
print_r($bucket); | |
} | |
print("\n\n"); | |
// create bucket | |
$result = $client->createBucket(array( | |
"Bucket" => "test" | |
)); | |
// PUT object | |
$client->putObject(array( | |
"Bucket" => "test", | |
"Key" => "key-test", | |
"Body" => "Hello, world!" | |
)); | |
// GET object | |
$object = $client->getObject(array( | |
"Bucket" => "test", | |
"Key" => "key-test" | |
)); | |
print($object->get("Body")); | |
print("\n\n"); | |
// HEAD object | |
$headers = $client->headObject(array( | |
"Bucket" => "test", | |
"Key" => "key-test" | |
)); | |
print_r($headers->toArray()); | |
// DELETE object | |
$client->deleteObject(array( | |
"Bucket" => "test", | |
"Key" => "key-test" | |
)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment