if_bucket_exists ( $bucket )

Gets whether or not the specified Amazon S3 bucket exists in Amazon S3. This includes buckets that do not belong to the caller.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to use.

Returns

Type

Description

boolean

A value of true if the bucket exists, or a value of false if it does not.

Examples

Check if a bucket exists in the S3 system.

Note: A successful response does NOT mean that you own the bucket.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

$response = $s3->if_bucket_exists($bucket);

// Success? (Boolean, not a CFResponse object)
var_dump($response);
Result:
bool(true)

Source

Method defined in services/s3.class.php | Toggle source view (10 lines) | View on GitHub

public function if_bucket_exists($bucket)
{
    if ($this->use_batch_flow)
    {
        throw new S3_Exception(__FUNCTION__ . '() cannot be batch requested');
    }

    $header = $this->get_bucket_headers($bucket);
    return (integer) $header->status !== 404;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback