PHP code example of aws / aws-sdk-php-resources
1. Go to this page and download the library: Download aws/aws-sdk-php-resources library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aws / aws-sdk-php-resources example snippets
ws\Resource\Aws;
$aws = new Aws($config);
// Get a resource representing the S3 service.
$s3 = $aws->s3;
$s3 = $aws->s3(['region' => 'eu-central-1']);
$bucket = $aws->s3->bucket('my-bucket');
$object = $bucket->object('image/bird.jpg');
echo $object['LastModified'];
print_r($object->getIdentity());
# Array
# (
# [BucketName] => my-bucket
# [Key] => image/bird.jpg
# )
print_r($object->getData());
# Array
# (
# ...
# )
// Create a bucket and object.
$bucket = $aws->s3->createBucket([
'Bucket' => 'my-new-bucket'
]);
$object = $bucket->putObject([
'Key' => 'images/image001.jpg',
'Body' => fopen('/path/to/image.jpg', 'r'),
]);
// Delete the bucket and object.
$object->delete();
$bucket->delete();
foreach ($bucket->objects() as $object) {
echo "Deleting object {$object['Key']}...\n";
$object->delete();
}
$messages = $queue->receiveMessages(['VisibilityTimeout' => 60]);
echo "Number of Messages Received: " . count($messages) . "\n";
echo "Receipt Handles:\n";
foreach ($messages as $message) {
echo "- {$message['ReceiptHandle']}\n";
$message->delete();
}
print_r($bucket->respondsTo());
# Array
# (
# [0] => create
# [1] => delete
# [2] => deleteObjects
# [3] => putObject
# [4] => multipartUploads
# [5] => objectVersions
# [6] => objects
# [7] => bucketAcl
# [8] => bucketCors
# [9] => bucketLifecycle
# [10] => bucketLogging
# [11] => bucketPolicy
# [12] => bucketNotification
# [13] => bucketRequestPayment
# [14] => bucketTagging
# [15] => bucketVersioning
# [16] => bucketWebsite
# [17] => object
# [18] => exists
# )
var_dump($bucket->respondsTo('putObject'));
# bool(true)
print_r($bucket->getMeta());
# Array
# (
# ...
# )