Skip to content

Commit a64cd91

Browse files
Merge pull request #37 from imshashank/master
Add example docs for AWS S3 Objects Operation
2 parents ced55f7 + 1b60634 commit a64cd91

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* This file is licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License. A copy of
7+
* the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0/
10+
*
11+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
*/
15+
16+
require 'vendor/autoload.php';
17+
18+
use Aws\S3\S3Client;
19+
use Aws\Exception\AwsException;
20+
21+
/**
22+
* Delete an Object inside Amazon S3.
23+
*
24+
* This code expects that you have AWS credentials set up per:
25+
* http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html
26+
*/
27+
28+
$USAGE = "\n" .
29+
"To run this example, supply the name of an S3 bucket and object\n" .
30+
"name (key) to delete.\n" .
31+
"\n" .
32+
"Ex: php DeleteObject.php <bucketname> <objectname>\n";
33+
34+
if (count($argv) <= 2){
35+
echo $USAGE;
36+
exit();
37+
}
38+
39+
$bucket = $argv[1];
40+
$key = $argv[2];
41+
42+
try{
43+
//Create a S3Client
44+
$s3Client = new S3Client([
45+
'region' => 'us-west-2',
46+
'version' => '2006-03-01'
47+
]);
48+
$result = $s3Client->deleteObject([
49+
'Bucket' => $bucket,
50+
'Key' => $key,
51+
]);
52+
} catch (S3Exception $e) {
53+
echo $e->getMessage() . "\n";
54+
}

php/example_code/s3/GetObject.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* This file is licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License. A copy of
7+
* the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0/
10+
*
11+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
*/
15+
16+
require 'vendor/autoload.php';
17+
18+
use Aws\S3\S3Client;
19+
use Aws\Exception\AwsException;
20+
21+
/**
22+
* Get/Download an Object from Amazon S3.
23+
*
24+
* This code expects that you have AWS credentials set up per:
25+
* http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html
26+
*/
27+
28+
$USAGE = "\n" .
29+
"To run this example, supply the name of an S3 bucket and object to\n" .
30+
"download from it.\n" .
31+
"\n" .
32+
"Ex: php GetObject.php <bucketname> <filename>\n";
33+
34+
if (count($argv) <= 2){
35+
echo $USAGE;
36+
exit();
37+
}
38+
39+
$bucket = $argv[1];
40+
$key = $argv[2];
41+
42+
try{
43+
//Create a S3Client
44+
$s3Client = new S3Client([
45+
'region' => 'us-west-2',
46+
'version' => '2006-03-01'
47+
]);
48+
// Save object to a file.
49+
$result = $s3Client->getObject(array(
50+
'Bucket' => $bucket,
51+
'Key' => $key,
52+
'SaveAs' => $key
53+
));
54+
} catch (S3Exception $e) {
55+
echo $e->getMessage() . "\n";
56+
}

php/example_code/s3/PutObject.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* This file is licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License. A copy of
7+
* the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0/
10+
*
11+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
*/
15+
16+
require 'vendor/autoload.php';
17+
18+
use Aws\S3\S3Client;
19+
use Aws\Exception\AwsException;
20+
21+
/**
22+
* Put an Object inside Amazon S3 Bucket.
23+
*
24+
* This code expects that you have AWS credentials set up per:
25+
* http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html
26+
*/
27+
28+
$USAGE = "\n" .
29+
"To run this example, supply the name of an S3 bucket and a file to\n" .
30+
"upload to it.\n" .
31+
"\n" .
32+
"Ex: php PutObject.php <bucketname> <filename>\n";
33+
34+
if (count($argv) <= 2){
35+
echo $USAGE;
36+
exit();
37+
}
38+
39+
$bucket = $argv[1];
40+
$file_Path = $argv[2];
41+
$key = basename($argv[2]);
42+
43+
try{
44+
//Create a S3Client
45+
$s3Client = new S3Client([
46+
'region' => 'us-west-2',
47+
'version' => '2006-03-01'
48+
]);
49+
$result = $s3Client->putObject([
50+
'Bucket' => $bucket,
51+
'Key' => $key,
52+
'SourceFile' => $file_Path,
53+
]);
54+
} catch (S3Exception $e) {
55+
echo $e->getMessage() . "\n";
56+
}

0 commit comments

Comments
 (0)