Я проверил это, и оно работает 2019-05-28
function Amazon_s3_delete_dir($delPath, $s3, $bucket) {
//the $dir is the path to the directory including the directory
// the directories need to have a / at the end.
// Clear it just in case it may or may not be there and then add it back in.
$dir = rtrim($dir, "/");
$dir = ltrim($dir, "/");
$dir = $dir . "/";
$response = $s3->getIterator(
'ListObjects',
[
'Bucket' => $bucket,
'Prefix' => $delPath
]
);
//delete each
foreach ($response as $object) {
$fileName = $object['Key'];
$s3->deleteObject([
'Bucket' => $bucket,
'Key' => $fileName
]);
}//foreach
return true;
}//function
Использование:
$delPath = $myDir . $theFolderName . "/";
Amazon_s3_delete_dir($delPath, $s3, $bucket);