判断桶是否存在

您可以使用 doesBucketExist 接口判断桶是否存在,以下代码展示如何判断一个桶是否存在:

$bucket = '<your-bucket-name>';
try {
    $exist = $s3Client->doesBucketExist($bucket);
    if ($exist) {
        echo "Bucket already exists.\n" . $bucket;
    }else{
        echo "Bucket doesn't exist.\n" . $bucket;
    }
} catch (S3Exception $e) {
    //打印错误信息
    echo $e->getMessage() . "\n";
}