获取桶访问权限

您可以使用 getBucketAcl 接口获取桶的访问权限。以下代码展示如何获取桶的访问权限:

$bucket = '<your-bucket-name>';
try {
    $resp = $s3Client->getBucketAcl([
        'Bucket' => $bucket
    ]);
    //打印获取的桶 owner displayname,ID 以及访问权限信息
    echo "Succeed in retrieving bucket ACL as follows: \n";
    echo 'Owner DisplayName: ' . $resp['Owner']['DisplayName'] . "\n";
    echo 'Owner ID: '           . $resp['Owner']['ID']          . "\n";
    foreach ($resp['Grants'] as $grant) {
        echo "Grant: \n";
        foreach($grant['Grantee'] as $k=>$val)
        {
            echo $k . ": " . $val . "\n";
        }
        echo 'Permission: ' . $grant['Permission'] . "\n";
    }
} catch (AwsException $e) {
    echo 'error:' . $e->getMessage();
    echo "\n";
}