@deprecated
Access
public
Parameters
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
|
Required |
||
|
|
Optional |
Examples
Create, get and delete an object expiration configuration.
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);
#--------------------------------------------------------------------#
# Create a new bucket
$response = $s3->create_bucket($bucket, AmazonS3::REGION_US_STANDARD);
if ($response->isOK())
{
// Give the bucket a moment to create
while (!$s3->if_bucket_exists($bucket))
{
sleep(1);
}
}
#--------------------------------------------------------------------#
# Create some files in the bucket
for ($i = 0; $i < 10; $i++)
{
$even = ($i % 2) ? 'odd' : 'even';
$s3->batch()->create_object($bucket, ($even . '/åéîøü' . $i), array(
'body' => 'sample text',
'contentType' => 'text/plain; charset=utf-8'
));
}
$responses = $s3->batch()->send();
if ($responses->areOK())
{
print_r($s3->get_object_list($bucket));
echo PHP_EOL;
}
#--------------------------------------------------------------------#
# Create an object expiration configuration
$response = $s3->create_object_expiration_config($bucket, array(
'rules' => array(
array(
'id' => 'unique-rule-identifier',
'prefix' => 'even/',
'expiration' => array(
'days' => 3
)
),
array(
'prefix' => 'odd/',
'expiration' => array(
'days' => 1
)
)
)
));
if ($response->isOK())
{
// Give the configuration a moment to settle in
while (!$s3->get_object_expiration_config($bucket)->isOK())
{
sleep(1);
}
}
#--------------------------------------------------------------------#
# Lookup the configuration
$response = $s3->get_object_expiration_config($bucket);
print_r($response->body);
echo PHP_EOL;
#--------------------------------------------------------------------#
# Delete the configuration
$response = $s3->delete_object_expiration_config($bucket);
if ($response->isOK())
{
// Delete the bucket
$response = $s3->delete_bucket($bucket, true);
if ($response->isOK())
{
echo 'Bucket was deleted!' . PHP_EOL;
}
else
{
echo 'Bucket deletion failed. #sadtromboneissad' . PHP_EOL;
}
}
Related Methods
Source
Method defined in services/s3.class.php | Toggle source view (4 lines) | View on GitHub

