use AwsS3S3Client;
$s3client = S3Client::factory ( [
'credentials' => [
'key' => 'Your aws key',
'secret' => 'Your aws secret key'
],
'region' => 'eu-west-1',
'version' => '2006-03-01'
] );
try {
$image_name_array=[];
$image_object=[];
$contents = $s3client->listObjects([
'Bucket' => 'bucket',
'Prefix' => 'public/uploads'
]);
foreach ($contents['Contents'] as $content) {
array_push($image_name_array,$content['Key']);
}
foreach($image_name_array as $image_key){
$result = $s3client->getObject([
'Bucket' => 'chemco',
'Key' => $image_key,
]);
header("Content-Type: {$result['ContentType']}");
array_push($image_object,$result['Body']);
}
foreach($image_object as $key=>$obj){
if($key==1){
echo $obj;
return $obj;
}
}
} catch (Exception $exception) {
echo "Failed to list objects in chemco with error: " . $exception->getMessage();
exit("Please fix error with listing objects before continuing.");
}