寫過又忘了,筆記一下,環境是 PHP 5.5.9:
<?php
require 'aws.phar'; // http://docs.aws.amazon.com/aws-sdk-php/v3/download/aws.phar //aws-3.27.5.phar
$s3 = Aws\S3\S3Client::factory(array(
'region' => 'us-west-2',
// http://docs.aws.amazon.com/aws-sdk-php/v3/api/index.html
'version' => '2006-03-01',
'credentials' => array(
'key' => 'key',
'secret' => 'secret',
),
));
try {
$result = $s3->putObject(array(
'Bucket' => 'my-bucket',
'Key' => 'my-object-key'
'SourceFile' => $_FILES['userfile']['tmp_name'],
));
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
print_r($result);
// $result['ObjectURL'];
Aws\Result Object
(
[data:Aws\Result:private] => Array
(
[Expiration] =>
[ETag] =>
[ServerSideEncryption] =>
[VersionId] =>
[SSECustomerAlgorithm] =>
[SSECustomerKeyMD5] =>
[SSEKMSKeyId] =>
[RequestCharged] =>
[@metadata] => Array
(
[statusCode] => 200
[effectiveUri] => https://s3-us-west-2.amazonaws.com/my-bucket/my-object-key
[headers] => Array
(
[x-amz-id-2] =>
[x-amz-request-id] =>
[date] =>
[etag] =>
[content-length] => 0
[server] => AmazonS3
)
[transferStats] => Array
(
[http] => Array
(
[0] => Array
(
)
)
)
)
[ObjectURL] => https://s3-us-west-2.amazonaws.com/my-bucket/my-object-key
)
)
沒有留言:
張貼留言