forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPutObjectServiceOperations.php
More file actions
53 lines (44 loc) · 1.61 KB
/
Copy pathPutObjectServiceOperations.php
File metadata and controls
53 lines (44 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/*
* ABOUT THIS PHP SAMPLE: This sample is part of the SDK for PHP Developer Guide topic at
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started/basic-usage.html
*
*/
// snippet-start:[s3.php.put_service_operations.complete]
// snippet-start:[s3.php.put_service_operations.import]
require 'vendor/autoload.php';
use Aws\S3\S3Client;
// snippet-end:[s3.php.put_service_operations.import]
/**
* Put an Object inside Amazon S3 Bucket.
*
* This code expects that you have AWS credentials set up per:
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
*/
// snippet-start:[s3.php.put_service_operations.main]
// Use the us-east-2 region and latest version of each client.
$sharedConfig = [
'profile' => 'default',
'region' => 'us-east-2'
];
// Create an SDK class used to share configuration across clients.
$sdk = new Aws\Sdk($sharedConfig);
// Use an Aws\Sdk class to create the S3Client object.
$s3Client = $sdk->createS3();
// Send a PutObject request and get the result object.
$result = $s3Client->putObject([
'Bucket' => 'amzn-s3-demo-bucket',
'Key' => 'my-key',
'Body' => 'this is the body!'
]);
// Download the contents of the object.
$result = $s3Client->getObject([
'Bucket' => 'amzn-s3-demo-bucket',
'Key' => 'my-key'
]);
// Print the body of the result by indexing into the result object.
echo $result['Body'];
// snippet-end:[s3.php.put_service_operations.main]
// snippet-end:[s3.php.put_service_operations.complete]