tldr;您有各种AWS SDK版本
>根据您在消息中提供的链接(link),您已经安装了php sdk v3
>根据您的示例,您使用PHP sdk v2
>创建一个客户端 – 简单的方法
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1'
]);
>创建一个客户端 – 使用sdk类
// Use the us-west-2 region and latest version of each client.
$sharedConfig = [
'region' => 'us-west-2',
'version' => 'latest'
];
// Create an SDK class used to share configuration across clients.
$sdk = new Aws\Sdk($sharedConfig);
// Create an Amazon S3 client using the shared configuration data.
$s3 = $sdk->createS3();
一旦你有你的客户端,你可以使用你现有的代码(是的,这个是v3)在s3上放置一个新对象,这样你就会得到像
// Include the AWS SDK using the Composer autoloader.
require '../vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$bucket = 'testbucket';
$keyname = 'test.txt';
// Instantiate the client.
-- select method 1 or 2 --
try {
// Upload data.
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => $keyname,
'Body' => 'Hello, world!',
'ACL' => 'public-read'
));
// Print the URL to the object.
echo $result['ObjectURL'] . "\n";
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}