我一直在尝试一段时间来设置上传到亚马逊S3服务的上传表单的基本PHP实现,但我无法获得任何工作。基本的AWS S3 PHP设置
通过阅读他们的文档,他们的例子看起来都不一样。 提供凭证并上传文件的正确方法是什么?
在他们的GitHub库,它说:
// Require the Composer autoloader.
require 'vendor/autoload.php';
use Aws\S3\S3Client;
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-west-2'
]);
try {
$s3->putObject([
'Bucket' => 'my-bucket',
'Key' => 'my-object',
'Body' => fopen('/path/to/file', 'r'),
'ACL' => 'public-read',
]);
} catch (Aws\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n";
}
在http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-s3.html他们说:
use Aws\S3\S3Client;
$client = S3Client::factory(array(
'profile' => '<profile in your aws credentials file>'
));
// Upload an object by streaming the contents of a file
// $pathToFile should be absolute path to a file on disk
$result = $client->putObject(array(
'Bucket' => $bucket,
'Key' => 'data_from_file.txt',
'SourceFile' => $pathToFile,
'Metadata' => array(
'Foo' => 'abc',
'Baz' => '123'
)
));
// We can poll the object until it is accessible
$client->waitUntil('ObjectExists', array(
'Bucket' => $this->bucket,
'Key' => 'data_from_file.txt'
));
人谁已经能够最近这样做可以阐明这里设置一些轻?
您是否收到任何电子邮件rrors? –
我一直使用这个指南。 http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-s3.html同时确保你已经安装了cURL扩展。 – Vector