[aws/aws-sdk-php 3.166.2] 複数画像をphpでS3にアップロード

$ composer require aws/aws-sdk-php

require_once "vendor/autoload.php";

$bucket = '';
$key = '';
$secret = '';

$s3client = new Aws\S3\S3Client([
    'credentials' => [
        'key' => $key,
        'secret' => $secret,
    ],
    'region' => 'ap-northeast-1',
    'version' => 'latest',
]);

$file = "img/flower.jpg";

$result = $s3client->putObject(array(
	'Bucket' => $bucket,
	'Key' => 'test/flower.jpg',
	'ACL' => 'public-read',
	'SourceFile' => $file,
	'ContentType' => mime_content_type($file),
));

echo "<pre>";
var_dump($result);
echo "</pre>";

これをファイル複数一括で行いたい。
複数ファイルの取得はglobだったかな。

foreach(glob("img/*.*") as $file) {
    $files[] = $file;
}

$s3client = new Aws\S3\S3Client([
    'credentials' => [
        'key' => $key,
        'secret' => $secret,
    ],
    'region' => 'ap-northeast-1',
    'version' => 'latest',
]);

foreach($files as $file){
		$result[] = $s3client->putObject(array(
		'Bucket' => $bucket,
		'Key' => $file,
		'ACL' => 'public-read',
		'SourceFile' => $file,
		'ContentType' => mime_content_type($file),
	));
}

echo "<pre>";
var_dump($result);
echo "</pre>";

ちょっと時間かかるな。手動でやった方が良さげ。