要在 AWS S3 上使用正确的 SSL 验证,应遵循以下步骤:
use Aws\S3\S3Client;
$client = S3Client::factory(array(
'credentials' => array(
'key' => 'your-aws-access-key-id',
'secret' => 'your-aws-secret-access-key',
),
'region' => 'your-aws-region',
'version' => 'latest',
'tls' => true, // enable SSL/TLS
));
use GuzzleHttp\Client as GuzzleClient;
$client = new GuzzleClient(array(
'defaults' => array(
'verify' => '/path/to/cert.pem', // path to CA certificate bundle file
),
));
// or
$client = new GuzzleClient(array(
'defaults' => array(
'verify' => true, // use system default CA certificate bundle file
),
));
use Aws\S3\S3Client;
$client = S3Client::factory(array(
'credentials' => array(
'key' => '...',
'secret' => '...',
),
'region' => '...',
'version' => 'latest',
'tls' => true,
));
$result = $client->getObject(array(
'Bucket' => 'my-bucket',
'Key' => 'my-object',
));
$headerObject = $client->getObject(array(
'Bucket' => 'my-bucket',
'Key' => 'my-object',
'ResponseContentDisposition' => 'attachment; filename="filename.jpg"',
));
echo $result['Body'];