delete_objects ( $bucket, $opt )

Deletes one or more specified Amazon S3 objects from the specified bucket.

Since delete_object() is designed for deleting a single object, this method is intended to be used when there are two or more objects to delete.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to use.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • objects - array - Required - The object references to delete from the bucket.
    • key - string - Required - The name of the object (e.g., the “key”) to delete. This should include the entire file path including all “subdirectories”.
    • version_id - string - Optional - If the object is versioned, include the version ID to delete.
  • quiet - boolean - Optional - Whether or not Amazon S3 should use “Quiet” mode for this operation. A value of true will enable Quiet mode. A value of false will use Verbose mode. The default value is false.
  • MFASerial - string - Optional - The serial number on the back of the Gemalto device. MFASerial and MFAToken must both be set for MFA to work.
  • MFAToken - string - Optional - The current token displayed on the Gemalto device. MFASerial and MFAToken must both be set for MFA to work.
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

See Also

Source

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

public function delete_objects($bucket, $opt = null)
{
    // Add this to our request
    if (!$opt) $opt = array();
    $opt['verb'] = 'POST';
    $opt['sub_resource'] = 'delete';
    $opt['body'] = '';

    // Bail out
    if (!isset($opt['objects']) || !is_array($opt['objects']))
    {
        throw new S3_Exception('The ' . __FUNCTION__ . ' method requires the "objects" option to be set as an array.');
    }

    $xml = new SimpleXMLElement($this->multi_object_delete_xml);

    // Add the objects
    foreach ($opt['objects'] as $object)
    {
        $xobject = $xml->addChild('Object');
        $node = $xobject->addChild('Key');
        $node[0] = $object['key'];

        if (isset($object['version_id']))
        {
            $xobject->addChild('VersionId', $object['version_id']);
        }
    }

    // Quiet mode?
    if (isset($opt['quiet']))
    {
        $quiet = 'false';
        if (is_bool($opt['quiet'])) // Boolean
        {
            $quiet = $opt['quiet'] ? 'true' : 'false';
        }
        elseif (is_string($opt['quiet'])) // String
        {
            $quiet = ($opt['quiet'] === 'true') ? 'true' : 'false';
        }

        $xml->addChild('Quiet', $quiet);
    }

    // Enable MFA delete?
    // @codeCoverageIgnoreStart
    if (isset($opt['MFASerial']) && isset($opt['MFAToken']))
    {
        $opt['headers'] = array(
            'x-amz-mfa' => ($opt['MFASerial'] . ' ' . $opt['MFAToken'])
        );
    }
    // @codeCoverageIgnoreEnd

    $opt['body'] = $xml->asXML();

    // Authenticate to S3
    return $this->authenticate($bucket, $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback