validate_bucketname_create ( $bucket )

Validates whether or not the specified Amazon S3 bucket name is valid for DNS-style access. This method is leveraged by any method that creates buckets.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to validate.

Returns

Type

Description

boolean

Whether or not the specified Amazon S3 bucket name is valid for DNS-style access. A value of true means that the bucket name is valid. A value of false means that the bucket name is invalid.

Related Methods

Source

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

public function validate_bucketname_create($bucket)
{
    // list_buckets() uses this. Let it pass.
    if ($bucket === '') return true;

    if (
        ($bucket === null || $bucket === false) ||                  // Must not be null or false
        preg_match('/[^(a-z0-9\-\.)]/', $bucket) ||                 // Must be in the lowercase Roman alphabet, period or hyphen
        !preg_match('/^([a-z]|\d)/', $bucket) ||                    // Must start with a number or letter
        !(strlen($bucket) >= 3 && strlen($bucket) <= 63) ||         // Must be between 3 and 63 characters long
        (strpos($bucket, '..') !== false) ||                        // Bucket names cannot contain two, adjacent periods
        (strpos($bucket, '-.') !== false) ||                        // Bucket names cannot contain dashes next to periods
        (strpos($bucket, '.-') !== false) ||                        // Bucket names cannot contain dashes next to periods
        preg_match('/(-|\.)$/', $bucket) ||                         // Bucket names should not end with a dash or period
        preg_match('/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/', $bucket)    // Must not be formatted as an IP address
    ) return false;

    return true;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback