我试图将.txt
文件发送到AWS中的s3bucket,但是每当我使用Mamp运行代码时,都会出现以下错误:
错误:在“ https://dynamics-bucket-qa.s3.eu-west-2.amazonaws.com/folder/Test.txt”上执行“ PutObject”时出错; AWS HTTP错误:cURL错误60:SSL证书问题:无法获取本地颁发者证书(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html)
我已将从互联网上下载的cacert.pem
文件放在MAMP的extra/ssl
文件夹中,并且还用此php.ini
毕竟,它仍然无法正常工作。我已经尝试了很长时间,但没有设法解决它。我对这一切都很陌生。
我正在使用PHP 7.2.10版
<?php
// Run:$ composer require aws/aws-sdk-php
require '../vendor/autoload.php';
use Aws\AwsClient;
use Aws\Exception\AwsException;
// AWS Info
$bucketName = 'dynamics-bucket-qa';
$IAM_KEY = 'XXXXXXXXXXXXXXXXXXXXXXX';
$IAM_SECRET = 'XXXXXXXXXXXXXXXX';
// Connect to AWS
try {
// You may need to change the region. It will say in the URL when the bucket is open
// and on creation.
$s3 = Aws\S3\S3Client::factory(
array(
'credentials' => array(
'key' => $IAM_KEY,
'secret' => $IAM_SECRET
),
'version' => 'latest',
'region' => 'eu-west-2'
)
);
} catch (Exception $e) {
die("Error: " . $e->getMessage());
}
// For this, I would generate a unqiue random string for the key name. But you can do whatever.
$keyName = 'folder/' . basename($_FILES["fileToUpload"]['name']);
$pathInS3 = 'https://s3.eu-west-2.amazonaws.com/' . $bucketName . '/' . $keyName;
// Add it to S3
try {
// Uploaded:
$file = $_FILES["fileToUpload"]['tmp_name'];
$s3->putObject(
array(
'Bucket'=>$bucketName,
'Key' => $keyName,
'SourceFile' => $file,
'StorageClass' => 'REDUCED_REDUNDANCY'
)
);
} catch (S3Exception $e) {
die('Error:' . $e->getMessage());
} catch (Exception $e) {
die('Error:' . $e->getMessage());
}
echo 'Done';
//htdocs composer -v
?>