/vendors/aws-sdk/services/s3.class.php
PHP | 3637 lines | 1508 code | 394 blank | 1735 comment | 241 complexity | c27938cdc812a42fe8018ad9cde9286e MD5 | raw file
Possible License(s): BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- * Copyright 2010 Amazon.com, Inc. or its affiliates. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License").
- * You may not use this file except in compliance with the License.
- * A copy of the License is located at
- *
- * http://aws.amazon.com/apache2.0
- *
- * or in the "license" file accompanying this file. This file is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
- * express or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
- /**
- * File: AmazonS3
- * Amazon S3 is a web service that enables you to store data in the cloud. You can then download the data
- * or use the data with other AWS services, such as Amazon Elastic Cloud Computer (EC2).
- *
- * Amazon Simple Storage Service (Amazon S3) is storage for the Internet. You can use Amazon S3 to store
- * and retrieve any amount of data at any time, from anywhere on the web. You can accomplish these tasks
- * using the AWS Management Console, which is a simple and intuitive web interface.
- *
- * To get the most out of Amazon S3, you need to understand a few simple concepts. Amazon S3 stores data
- * as objects in buckets. An object is comprised of a file and optionally any metadata that describes
- * that file.
- *
- * To store an object in Amazon S3, you upload the file you want to store to a bucket. When you upload a
- * file, you can set permissions on the object as well as any metadata.
- *
- * Buckets are the containers for objects. You can have one or more buckets. For each bucket, you can control
- * access to the bucket (who can create, delete, and list objects in the bucket), view access logs for the
- * bucket and its objects, and choose the geographical region where Amazon S3 will store the bucket and its
- * contents.
- *
- * Visit <http://aws.amazon.com/s3/> for more information.
- *
- * Version:
- * 2010.12.02
- *
- * License and Copyright:
- * See the included NOTICE.md file for more information.
- *
- * See Also:
- * [Amazon Simple Storage Service](http://aws.amazon.com/s3/)
- * [Amazon Simple Storage Service documentation](http://aws.amazon.com/documentation/s3/)
- */
- /*%******************************************************************************************%*/
- // EXCEPTIONS
- /**
- * Exception: S3_Exception
- * Default S3 Exception.
- */
- class S3_Exception extends Exception {}
- /*%******************************************************************************************%*/
- // MAIN CLASS
- /**
- * Class: AmazonS3
- * Container for all Amazon S3-related methods. Inherits additional methods from CFRuntime.
- */
- class AmazonS3 extends CFRuntime
- {
- /*%******************************************************************************************%*/
- // CLASS CONSTANTS
- /**
- * Constant: DEFAULT_URL
- * The default endpoint.
- */
- const DEFAULT_URL = 's3.amazonaws.com';
- /**
- * Constant: REGION_US_E1
- * Specify the queue URL for the US-East (Northern Virginia) Region.
- */
- const REGION_US_E1 = '';
- /**
- * Constant: REGION_US_W1
- * Specify the queue URL for the US-West (Northern California) Region.
- */
- const REGION_US_W1 = 'us-west-1';
- /**
- * Constant: REGION_EU_W1
- * Specify the queue URL for the EU (Ireland) Region.
- */
- const REGION_EU_W1 = 'EU';
- /**
- * Constant: REGION_APAC_SE1
- * Specify the queue URL for the Asia Pacific (Singapore) Region.
- */
- const REGION_APAC_SE1 = 'ap-southeast-1';
- /**
- * Constant: ACL_PRIVATE
- * ACL: Owner-only read/write.
- */
- const ACL_PRIVATE = 'private';
- /**
- * Constant: ACL_PUBLIC
- * ACL: Owner read/write, public read.
- */
- const ACL_PUBLIC = 'public-read';
- /**
- * Constant: ACL_OPEN
- * ACL: Public read/write.
- */
- const ACL_OPEN = 'public-read-write';
- /**
- * Constant: ACL_AUTH_READ
- * ACL: Owner read/write, authenticated read.
- */
- const ACL_AUTH_READ = 'authenticated-read';
- /**
- * Constant: ACL_OWNER_READ
- * ACL: Bucket owner read.
- */
- const ACL_OWNER_READ = 'bucket-owner-read';
- /**
- * Constant: ACL_OWNER_FULL_CONTROL
- * ACL: Bucket owner full control.
- */
- const ACL_OWNER_FULL_CONTROL = 'bucket-owner-full-control';
- /**
- * Constant: GRANT_READ
- * When applied to a bucket, grants permission to list the bucket. When applied to an object, this
- * grants permission to read the object data and/or metadata.
- */
- const GRANT_READ = 'READ';
- /**
- * Constant: GRANT_WRITE
- * When applied to a bucket, grants permission to create, overwrite, and delete any object in the
- * bucket. This permission is not supported for objects.
- */
- const GRANT_WRITE = 'WRITE';
- /**
- * Constant: GRANT_READ_ACP
- * Grants permission to read the ACL for the applicable bucket or object. The owner of a bucket or
- * object always has this permission implicitly.
- */
- const GRANT_READ_ACP = 'READ_ACP';
- /**
- * Constant: GRANT_WRITE_ACP
- * Gives permission to overwrite the ACP for the applicable bucket or object. The owner of a bucket
- * or object always has this permission implicitly. Granting this permission is equivalent to granting
- * FULL_CONTROL because the grant recipient can make any changes to the ACP.
- */
- const GRANT_WRITE_ACP = 'WRITE_ACP';
- /**
- * Constant: GRANT_FULL_CONTROL
- * Provides READ, WRITE, READ_ACP, and WRITE_ACP permissions. It does not convey additional rights and
- * is provided only for convenience.
- */
- const GRANT_FULL_CONTROL = 'FULL_CONTROL';
- /**
- * Constant: USERS_AUTH
- * The "AuthenticatedUsers" group for access control policies.
- */
- const USERS_AUTH = 'http://acs.amazonaws.com/groups/global/AuthenticatedUsers';
- /**
- * Constant: USERS_ALL
- * The "AllUsers" group for access control policies.
- */
- const USERS_ALL = 'http://acs.amazonaws.com/groups/global/AllUsers';
- /**
- * Constant: USERS_LOGGING
- * The "LogDelivery" group for access control policies.
- */
- const USERS_LOGGING = 'http://acs.amazonaws.com/groups/s3/LogDelivery';
- /**
- * Constant: PCRE_ALL
- * PCRE: Match all items
- */
- const PCRE_ALL = '/.*/i';
- /**
- * Constant: STORAGE_STANDARD
- * Standard storage redundancy.
- */
- const STORAGE_STANDARD = 'STANDARD';
- /**
- * Constant: STORAGE_REDUCED
- * Reduced storage redundancy.
- */
- const STORAGE_REDUCED = 'REDUCED_REDUNDANCY';
- /*%******************************************************************************************%*/
- // PROPERTIES
- /**
- * Property: request_url
- * The request URL.
- */
- public $request_url;
- /**
- * Property: vhost
- * The virtual host setting.
- */
- public $vhost;
- /**
- * Property: base_acp_xml
- * The base XML elements to use for access control policy methods.
- */
- public $base_acp_xml;
- /**
- * Property: base_logging_xml
- * The base XML elements to use for logging methods.
- */
- public $base_logging_xml;
- /**
- * Property: base_notification_xml
- * The base XML elements to use for notifications.
- */
- public $base_notification_xml;
- /**
- * Property: base_versioning_xml
- * The base XML elements to use for versioning.
- */
- public $base_versioning_xml;
- /**
- * Property: complete_mpu_xml
- * The base XML elements to use for completing a multipart upload.
- */
- public $complete_mpu_xml;
- /**
- * Property: path_style
- * The DNS vs. Path-style setting.
- */
- public $path_style = false;
- /*%******************************************************************************************%*/
- // CONSTRUCTOR
- /**
- * Method: __construct()
- * Constructs a new instance of <AmazonS3>.
- *
- * Access:
- * public
- *
- * Parameters:
- * $key - _string_ (Optional) Amazon API Key. If blank, the <AWS_KEY> constant is used.
- * $secret_key - _string_ (Optional) Amazon API Secret Key. If blank, the <AWS_SECRET_KEY> constant is used.
- *
- * Returns:
- * _boolean_ A value of `false` if no valid values are set, otherwise `true`.
- */
- public function __construct($key = null, $secret_key = null)
- {
- $this->vhost = null;
- $this->api_version = '2006-03-01';
- $this->hostname = self::DEFAULT_URL;
- $this->base_acp_xml = '<?xml version="1.0" encoding="UTF-8"?><AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/latest/"></AccessControlPolicy>';
- $this->base_location_constraint = '<?xml version="1.0" encoding="UTF-8"?><CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LocationConstraint></LocationConstraint></CreateBucketConfiguration>';
- $this->base_logging_xml = '<?xml version="1.0" encoding="utf-8"?><BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/' . $this->api_version . '"></BucketLoggingStatus>';
- $this->base_notification_xml = '<?xml version="1.0" encoding="utf-8"?><NotificationConfiguration></NotificationConfiguration>';
- $this->base_versioning_xml = '<?xml version="1.0" encoding="utf-8"?><VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></VersioningConfiguration>';
- $this->complete_mpu_xml = '<?xml version="1.0" encoding="utf-8"?><CompleteMultipartUpload></CompleteMultipartUpload>';
- if (!$key && !defined('AWS_KEY'))
- {
- throw new S3_Exception('No account key was passed into the constructor, nor was it set in the AWS_KEY constant.');
- }
- if (!$secret_key && !defined('AWS_SECRET_KEY'))
- {
- throw new S3_Exception('No account secret was passed into the constructor, nor was it set in the AWS_SECRET_KEY constant.');
- }
- return parent::__construct($key, $secret_key);
- }
- /*%******************************************************************************************%*/
- // AUTHENTICATION
- /**
- * Method: authenticate()
- * Authenticates a connection to Amazon S3. Do not use directly unless implementing custom methods for
- * this class.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $opt - _array_ (Optional) An associative array of parameters for authenticating. See the individual methods for allowed keys.
- * $location - _string_ (Do Not Use) Used internally by this function on occasions when Amazon S3 returns a redirect code and it needs to call itself recursively.
- * $redirects - _integer_ (Do Not Use) Used internally by this function on occasions when Amazon S3 returns a redirect code and it needs to call itself recursively.
- *
- * Returns:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- *
- * See Also:
- * [REST authentication](http://docs.amazonwebservices.com/AmazonS3/latest/RESTAuthentication.html)
- */
- public function authenticate($bucket, $opt = null, $location = null, $redirects = 0, $nothing = null)
- {
- /*
- * Overriding or extending this class? You can pass the following "magic" keys into $opt.
- *
- * ## verb, resource, sub_resource and query_string ##
- * <verb> /<resource>?<sub_resource>&<query_string>
- * GET /filename.txt?versions&prefix=abc&max-items=1
- *
- * ## versionId, uploadId, partNumber ##
- * These don't follow the same rules as above, in that the they needs to be signed, while
- * other query_string values do not.
- *
- * ## curlopts ##
- * These values get passed directly to the cURL methods in RequestCore.
- *
- * ## fileUpload, fileDownload, seekTo, length ##
- * These are slightly modified and then passed to the cURL methods in RequestCore.
- *
- * ## headers ##
- * $opt['headers'] is an array, whose keys are HTTP headers to be sent.
- *
- * ## body ##
- * This is the request body that is sent to the server via PUT/POST.
- *
- * ## preauth ##
- * This is a hook that tells authenticate() to generate a pre-authenticated URL.
- *
- * ## returnCurlHandle ##
- * Tells authenticate() to return the cURL handle for the request instead of executing it.
- */
- /**
- * @todo: Handle duplicate headers with different values.
- */
- // Validate the S3 bucket name
- if (!$this->validate_bucketname_support($bucket))
- {
- throw new S3_Exception('S3 does not support "' . $bucket . '" as a valid bucket name. Review "Bucket Restrictions and Limitations" in the S3 Developer Guide for more information.');
- }
- // Die if $opt isn't set.
- if (!$opt) return false;
- $method_arguments = func_get_args();
- // Use the caching flow to determine if we need to do a round-trip to the server.
- if ($this->use_cache_flow)
- {
- // Generate an identifier specific to this particular set of arguments.
- $cache_id = $this->key . '_' . get_class($this) . '_' . $bucket . '_' . sha1(serialize($method_arguments));
- // Instantiate the appropriate caching object.
- $this->cache_object = new $this->cache_class($cache_id, $this->cache_location, $this->cache_expires, $this->cache_compress);
- if ($this->delete_cache)
- {
- $this->use_cache_flow = false;
- $this->delete_cache = false;
- return $this->cache_object->delete();
- }
- // Invoke the cache callback function to determine whether to pull data from the cache or make a fresh request.
- $data = $this->cache_object->response_manager(array($this, 'cache_callback'), $method_arguments);
- // Parse the XML body
- $data = $this->parse_callback($data);
- // End!
- return $data;
- }
- // If we haven't already set a resource prefix...
- if (!$this->resource_prefix || $this->path_style)
- {
- // And if the bucket name isn't DNS-valid...
- if (!$this->validate_bucketname_create($bucket) || $this->path_style)
- {
- // Fall back to the older path-style URI
- $this->set_resource_prefix('/' . $bucket);
- }
- }
- // Determine hostname
- $scheme = $this->use_ssl ? 'https://' : 'http://';
- if ($this->resource_prefix || $this->path_style) // Use bucket-in-path method.
- {
- $hostname = $this->hostname . $this->resource_prefix . (($bucket === '' || $this->resource_prefix === '/' . $bucket) ? '' : ('/' . $bucket));
- }
- else
- {
- $hostname = $this->vhost ? $this->vhost : (($bucket === '') ? $this->hostname : ($bucket . '.') . $this->hostname);
- }
- // Get the UTC timestamp in RFC 2616 format
- $date = gmdate($this->util->konst($this->util, 'DATE_FORMAT_RFC2616'), (time() + (integer) $this->adjust_offset));
- // Storage for request parameters.
- $resource = '';
- $sub_resource = '';
- $query_string_params = array();
- $signable_query_string_params = array();
- $string_to_sign = '';
- $headers = array(
- 'Content-MD5' => '',
- 'Content-Type' => 'application/x-www-form-urlencoded',
- 'Date' => $date
- );
- /*%******************************************************************************************%*/
- // Handle specific resources
- if (isset($opt['resource']))
- {
- $resource .= $opt['resource'];
- }
- // Merge query string values
- if (isset($opt['query_string']))
- {
- $query_string_params = array_merge($query_string_params, $opt['query_string']);
- }
- $query_string = $this->util->to_query_string($query_string_params);
- // Merge the signable query string values. Must be alphabetical.
- if (isset($opt['partNumber']))
- {
- $signable_query_string_params['partNumber'] = rawurlencode($opt['partNumber']);
- }
- if (isset($opt['uploadId']))
- {
- $signable_query_string_params['uploadId'] = rawurlencode($opt['uploadId']);
- }
- if (isset($opt['versionId']))
- {
- $signable_query_string_params['versionId'] = rawurlencode($opt['versionId']);
- }
- // ksort($signable_query_string_params);
- $signable_query_string = $this->util->to_query_string($signable_query_string_params);
- // Merge the HTTP headers
- if (isset($opt['headers']))
- {
- $headers = array_merge($headers, $opt['headers']);
- }
- // Compile the URI to request
- $conjunction = '?';
- $signable_resource = '/' . rawurlencode($resource);
- $non_signable_resource = '';
- if (isset($opt['sub_resource']))
- {
- $signable_resource .= $conjunction . rawurlencode($opt['sub_resource']);
- $conjunction = '&';
- }
- if ($signable_query_string !== '')
- {
- $signable_resource .= $conjunction . $signable_query_string;
- $conjunction = '&';
- }
- if ($query_string !== '')
- {
- $non_signable_resource .= $conjunction . $query_string;
- $conjunction = '&';
- }
- $this->request_url = $scheme . $hostname . $signable_resource . $non_signable_resource;
- // Instantiate the request class
- $request = new $this->request_class($this->request_url, $this->proxy);
- // Update RequestCore settings
- $request->request_class = $this->request_class;
- $request->response_class = $this->response_class;
- // Streaming uploads
- if (isset($opt['fileUpload']))
- {
- if (is_resource($opt['fileUpload']))
- {
- $request->set_read_stream($opt['fileUpload'], isset($opt['length']) ? $opt['length'] : -1);
- if ($headers['Content-Type'] === 'application/x-www-form-urlencoded')
- {
- $headers['Content-Type'] = 'application/octet-stream';
- }
- }
- else
- {
- $request->set_read_file($opt['fileUpload']);
- // Attempt to guess the correct mime-type
- if ($headers['Content-Type'] === 'application/x-www-form-urlencoded')
- {
- $extension = explode('.', $opt['fileUpload']);
- $extension = array_pop($extension);
- $mime_type = CFMimeTypes::get_mimetype($extension);
- $headers['Content-Type'] = $mime_type;
- }
- }
- $headers['Content-Length'] = $request->read_stream_size;
- $curlopts[CURLOPT_INFILESIZE] = $headers['Content-Length'];
- $headers['Content-MD5'] = '';
- }
- // Streaming downloads
- if (isset($opt['fileDownload']))
- {
- if (is_resource($opt['fileDownload']))
- {
- $request->set_write_stream($opt['fileDownload']);
- }
- else
- {
- $request->set_write_file($opt['fileDownload']);
- }
- }
- $curlopts = array();
- // Set custom CURLOPT settings
- if (isset($opt['curlopts']))
- {
- $curlopts = $opt['curlopts'];
- unset($opt['curlopts']);
- }
- // Debug mode
- if ($this->debug_mode)
- {
- $curlopts[CURLOPT_VERBOSE] = true;
- }
- // Handle streaming file offsets
- if (isset($opt['seekTo']))
- {
- // Pass the seek position to RequestCore
- $request->set_seek_position((integer) $opt['seekTo']);
- $headers['Content-Length'] = (!is_resource($opt['fileUpload']) ? (filesize($opt['fileUpload']) - (integer) $opt['seekTo']) : -1);
- $curlopts[CURLOPT_INFILESIZE] = $headers['Content-Length'];
- }
- // Override the content length
- if (isset($opt['length']))
- {
- $headers['Content-Length'] = (integer) $opt['length'];
- $curlopts[CURLOPT_INFILESIZE] = $headers['Content-Length'];
- }
- // Set the curl options.
- if (count($curlopts))
- {
- $request->set_curlopts($curlopts);
- }
- // Do we have a verb?
- if (isset($opt['verb']))
- {
- $request->set_method($opt['verb']);
- $string_to_sign .= $opt['verb'] . "\n";
- }
- // Add headers and content when we have a body
- if (isset($opt['body']))
- {
- $request->set_body($opt['body']);
- $headers['Content-Length'] = strlen($opt['body']);
- if ($headers['Content-Type'] === 'application/x-www-form-urlencoded')
- {
- $headers['Content-Type'] = 'application/octet-stream';
- }
- if (!isset($opt['NoContentMD5']) || $opt['NoContentMD5'] !== true)
- {
- $headers['Content-MD5'] = $this->util->hex_to_base64(md5($opt['body']));
- }
- }
- // Handle query-string authentication
- if (isset($opt['preauth']) && (integer) $opt['preauth'] > 0)
- {
- unset($headers['Date']);
- $headers['Content-Type'] = '';
- $headers['Expires'] = strtotime($opt['preauth']);
- }
- // Sort headers
- uksort($headers, 'strnatcasecmp');
- // Add headers to request and compute the string to sign
- foreach ($headers as $header_key => $header_value)
- {
- // Strip linebreaks from header values as they're illegal and can allow for security issues
- $header_value = str_replace(array("\r", "\n"), '', $header_value);
- // Add the header if it has a value
- if ($header_value !== '')
- {
- $request->add_header($header_key, $header_value);
- }
- // Generate the string to sign
- if (
- strtolower($header_key) === 'content-md5' ||
- strtolower($header_key) === 'content-type' ||
- strtolower($header_key) === 'date' ||
- (strtolower($header_key) === 'expires' && isset($opt['preauth']) && (integer) $opt['preauth'] > 0)
- )
- {
- $string_to_sign .= $header_value . "\n";
- }
- elseif (substr(strtolower($header_key), 0, 6) === 'x-amz-')
- {
- $string_to_sign .= strtolower($header_key) . ':' . $header_value . "\n";
- }
- }
- // Add the signable resource location
- $string_to_sign .= ($this->resource_prefix ? $this->resource_prefix : '');
- $string_to_sign .= (($bucket === '' || $this->resource_prefix === '/' . $bucket) ? '' : ('/' . $bucket)) . $signable_resource;
- // Hash the AWS secret key and generate a signature for the request.
- $signature = base64_encode(hash_hmac('sha1', $string_to_sign, $this->secret_key, true));
- $request->add_header('Authorization', 'AWS ' . $this->key . ':' . $signature);
- // If we're generating a URL, return certain data to the calling method.
- if (isset($opt['preauth']) && (integer) $opt['preauth'] > 0)
- {
- return $this->request_url . (isset($opt['sub_resource']) ? '&' : '?') . 'AWSAccessKeyId=' . $this->key . '&Expires=' . $headers['Expires'] . '&Signature=' . rawurlencode($signature);
- }
- elseif (isset($opt['preauth']))
- {
- return $this->request_url;
- }
- /*%******************************************************************************************%*/
- // Manage the (newer) batch request API or the (older) returnCurlHandle setting.
- if ($this->use_batch_flow)
- {
- $handle = $request->prep_request();
- $this->batch_object->add($handle);
- $this->use_batch_flow = false;
- return $handle;
- }
- elseif (isset($opt['returnCurlHandle']) && $opt['returnCurlHandle'] === true)
- {
- return $request->prep_request();
- }
- // Send!
- $request->send_request();
- // Prepare the response
- $headers = $request->get_response_header();
- $headers['x-aws-request-url'] = $this->request_url;
- $headers['x-aws-redirects'] = $redirects;
- $headers['x-aws-stringtosign'] = $string_to_sign;
- $headers['x-aws-requestheaders'] = $request->request_headers;
- // Did we have a request body?
- if (isset($opt['body']))
- {
- $headers['x-aws-requestbody'] = $opt['body'];
- }
- $data = new $this->response_class($headers, $this->parse_callback($request->get_response_body()), $request->get_response_code());
- // Did Amazon tell us to redirect? Typically happens for multiple rapid requests EU datacenters.
- // @see: http://docs.amazonwebservices.com/AmazonS3/latest/Redirects.html
- if ((integer) $request->get_response_code() === 307) // Temporary redirect to new endpoint.
- {
- $data = $this->authenticate($bucket, $opt, $headers['location'], ++$redirects);
- }
- // Was it Amazon's fault the request failed? Retry the request until we reach $max_retries.
- elseif ((integer) $request->get_response_code() === 500 || (integer) $request->get_response_code() === 503)
- {
- if ($redirects <= $this->max_retries)
- {
- // Exponential backoff
- $delay = (integer) (pow(4, $redirects) * 100000);
- usleep($delay);
- $data = $this->authenticate($bucket, $opt, null, ++$redirects);
- }
- }
- // Return!
- return $data;
- }
- /**
- * Method: validate_bucketname_create()
- * 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:
- * $bucket - _string_ (Required) The name of the bucket to validate.
- *
- * Returns:
- * _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.
- */
- 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;
- }
- /**
- * Method: validate_bucketname_support()
- * Validates whether or not the specified Amazon S3 bucket name is valid for path-style access. This
- * method is leveraged by any method that reads from buckets.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to validate.
- *
- * Returns:
- * _boolean_ Whether or not the bucket name is valid. A value of `true` means that the bucket name is valid. A valuf of `false` means that the bucket name is invalid.
- */
- public function validate_bucketname_support($bucket)
- {
- // list_buckets() uses this. Let it pass.
- if ($bucket === '') return true;
- // Validate
- if (
- ($bucket === null || $bucket === false) || // Must not be null or false
- preg_match('/[^(a-z0-9_\-\.)]/i', $bucket) || // Must be in the Roman alphabet, period, hyphen or underscore
- !preg_match('/^([a-z]|\d)/i', $bucket) || // Must start with a number or letter
- !(strlen($bucket) >= 3 && strlen($bucket) <= 255) || // Must be between 3 and 255 characters long
- preg_match('/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/', $bucket) // Must not be formatted as an IP address
- ) return false;
- return true;
- }
- /**
- * Method: cache_callback()
- * The callback function that is executed when the cache doesn't exist or has expired. The response of
- * this method is cached. Accepts identical parameters as the <authenticate()> method. Never call this
- * method directly -- it is used internally by the caching system.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $opt - _array_ (Optional) An associative array of parameters for authenticating. See the individual methods for allowed keys.
- * $location - _string_ (Optional) Used internally by this method when Amazon S3 returns a redirect code and needs to call itself recursively.
- * $redirects - _integer_ (Optional) Used internally by this method when Amazon S3 returns a redirect code and needs to call itself recursively.
- *
- * Returns:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- */
- public function cache_callback($bucket, $opt = null, $location = null, $redirects = 0)
- {
- // Disable the cache flow since it's already been handled.
- $this->use_cache_flow = false;
- // Make the request
- $response = $this->authenticate($bucket, $opt, $location, $redirects);
- if (isset($response->body) && ($response->body instanceof SimpleXMLElement))
- {
- $response->body = $response->body->asXML();
- }
- return $response;
- }
- /*%******************************************************************************************%*/
- // SETTERS
- /**
- * Method: set_region()
- * Sets the region to use for subsequent Amazon S3 operations. This will also reset any prior use of
- * <enable_path_style()>.
- *
- * Access:
- * public
- *
- * Parameters:
- * $region - _string_ (Required) The region to use for subsequent Amazon S3 operations. [Allowed values: `AmazonS3::REGION_US_E1 `, `AmazonS3::REGION_US_W1`, `AmazonS3::REGION_EU_W1`, `AmazonS3::REGION_APAC_SE1`]
- *
- * Returns:
- * `$this` A reference to the current instance.
- */
- public function set_region($region)
- {
- switch ($region)
- {
- case self::REGION_US_W1: // Northern California
- case self::REGION_APAC_SE1: // Singapore
- $this->set_hostname('s3-' . $region . '.amazonaws.com');
- $this->enable_path_style(false);
- break;
- case self::REGION_EU_W1: // Ireland
- $this->set_hostname('s3-eu-west-1.amazonaws.com');
- $this->enable_path_style(); // Always use path-style access for EU endpoint.
- break;
- default:
- // REGION_US_E1 // Northern Virginia
- $this->set_hostname(self::DEFAULT_URL);
- $this->enable_path_style(false);
- break;
- }
- return $this;
- }
- /**
- * Method: set_vhost()
- * Sets the virtual host to use in place of the default `bucket.s3.amazonaws.com` domain.
- *
- * Access:
- * public
- *
- * Parameters:
- * $vhost - _string_ (Required) The virtual host to use in place of the default `bucket.s3.amazonaws.com` domain.
- *
- * Returns:
- * `$this` A reference to the current instance.
- *
- * See Also:
- * [Virtual Hosting of Buckets](http://docs.amazonwebservices.com/AmazonS3/latest/VirtualHosting.html)
- */
- public function set_vhost($vhost)
- {
- $this->vhost = $vhost;
- return $this;
- }
- /**
- * Method: enable_path_style()
- * Enables the use of the older path-style URI access for all requests.
- *
- * Access:
- * public
- *
- * Parameters:
- * $style - _string_ (Optional) Whether or not to enable path-style URI access for all requests. The default value is `true`.
- *
- * Returns:
- * `$this` A reference to the current instance.
- */
- public function enable_path_style($style = true)
- {
- $this->path_style = $style;
- return $this;
- }
- /*%******************************************************************************************%*/
- // BUCKET METHODS
- /**
- * Method: create_bucket()
- * Creates an Amazon S3 bucket.
- *
- * Every object stored in Amazon S3 is contained in a bucket. Buckets partition the namespace of
- * objects stored in Amazon S3 at the top level. in a bucket, any name can be used for objects.
- * However, bucket names must be unique across all of Amazon S3.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to create.
- * $region - _string_ (Required) The preferred geographical location for the bucket. [Allowed values: `AmazonS3::REGION_US_E1 `, `AmazonS3::REGION_US_W1`, `AmazonS3::REGION_EU_W1`, `AmazonS3::REGION_APAC_SE1`]
- * $acl - _string_ (Optional) The ACL settings for the specified bucket. [Allowed values: `AmazonS3::ACL_PRIVATE`, `AmazonS3::ACL_PUBLIC`, `AmazonS3::ACL_OPEN`, `AmazonS3::ACL_AUTH_READ`, `AmazonS3::ACL_OWNER_READ`, `AmazonS3::ACL_OWNER_FULL_CONTROL`]. The default value is <ACL_PRIVATE>.
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * 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:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- *
- * See Also:
- * * [Working with Amazon S3 Buckets](http://docs.amazonwebservices.com/AmazonS3/latest/UsingBucket.html)
- */
- public function create_bucket($bucket, $region, $acl = self::ACL_PRIVATE, $opt = null)
- {
- // If the bucket contains uppercase letters...
- if (preg_match('/[A-Z]/', $bucket))
- {
- // Throw a warning
- trigger_error('Since DNS-valid bucket names cannot contain uppercase characters, "' . $bucket . '" has been automatically converted to "' . strtolower($bucket) . '"', E_USER_WARNING);
- // Force the bucketname to lowercase
- $bucket = strtolower($bucket);
- }
- // Validate the S3 bucket name for creation
- if (!$this->validate_bucketname_create($bucket))
- {
- throw new S3_Exception('"' . $bucket . '" is not DNS-valid (i.e., <bucketname>.s3.amazonaws.com), and cannot be used as an S3 bucket name. Review "Bucket Restrictions and Limitations" in the S3 Developer Guide for more information.');
- }
- if (!$opt) $opt = array();
- $opt['verb'] = 'PUT';
- $opt['headers'] = array(
- 'Content-Type' => 'application/xml',
- 'x-amz-acl' => $acl
- );
- // Defaults
- $this->set_region($region);
- $xml = simplexml_load_string($this->base_location_constraint);
- switch ($region)
- {
- case self::REGION_US_W1: // Northern California
- case self::REGION_APAC_SE1: // Singapore
- $xml->LocationConstraint = $region;
- $opt['body'] = $xml->asXML();
- break;
- case self::REGION_EU_W1: // Ireland
- $this->enable_path_style(); // DNS-style doesn't seem to work for creation, only in EU. Switch over to path-style.
- $xml->LocationConstraint = $region;
- $opt['body'] = $xml->asXML();
- break;
- default: // REGION_US_E1 // Northern Virginia
- $opt['body'] = '';
- break;
- }
- $response = $this->authenticate($bucket, $opt);
- return $response;
- }
- /**
- * Method: get_bucket_region()
- * Gets the region in which the specified Amazon S3 bucket is located.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * preauth - _integer_|_string_ (Optional) Specifies that a presigned URL for this request should be returned. May be passed as a number of seconds since UNIX Epoch, or any string compatible with `strtotime()`.
- * 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:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- */
- public function get_bucket_region($bucket, $opt = null)
- {
- // Add this to our request
- if (!$opt) $opt = array();
- $opt['verb'] = 'GET';
- $opt['sub_resource'] = 'location';
- // Authenticate to S3
- $response = $this->authenticate($bucket, $opt);
- if ($response->isOK())
- {
- // Handle body
- $response->body = (string) $response->body;
- }
- return $response;
- }
- /**
- * Method: get_bucket_headers()
- * Gets the HTTP headers for the specified Amazon S3 bucket.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * preauth - _integer_|_string_ (Optional) Specifies that a presigned URL for this request should be returned. May be passed as a number of seconds since UNIX Epoch, or any string compatible with `strtotime()`.
- * 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:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- */
- public function get_bucket_headers($bucket, $opt = null)
- {
- if (!$opt) $opt = array();
- $opt['verb'] = 'HEAD';
- return $this->authenticate($bucket, $opt);
- }
- /**
- * Method: delete_bucket()
- * Deletes a bucket from an Amazon S3 account. A bucket must be empty before the bucket itself can be
- * deleted.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $force - _boolean_ (Optional) Whether to force-delete the bucket and all of its contents. The default value is `false`.
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * 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:
- * _mixed_ A <CFResponse> object if the bucket was deleted successfully. Returns _boolean_ `false` if otherwise.
- */
- public function delete_bucket($bucket, $force = false, $opt = null)
- {
- // Set default value
- $success = true;
- if ($force)
- {
- // Delete all of the items from the bucket.
- $success = $this->delete_all_object_versions($bucket);
- }
- // As long as we were successful...
- if ($success)
- {
- if (!$opt) $opt = array();
- $opt['verb'] = 'DELETE';
- return $this->authenticate($bucket, $opt);
- }
- return false;
- }
- /**
- * Method: list_buckets()
- * Gets a list of all buckets contained in the caller's Amazon S3 account.
- *
- * Access:
- * public
- *
- * Parameters:
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * preauth - _integer_|_string_ (Optional) Specifies that a presigned URL for this request should be returned. May be passed as a number of seconds since UNIX Epoch, or any string compatible with `strtotime()`.
- * 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:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- */
- public function list_buckets($opt = null)
- {
- if (!$opt) $opt = array();
- $opt['verb'] = 'GET';
- return $this->authenticate('', $opt);
- }
- /**
- * Method: get_bucket_acl()
- * Gets the access control list (ACL) settings for the specified Amazon S3 bucket.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * preauth - _integer_|_string_ (Optional) Specifies that a presigned URL for this request should be returned. May be passed as a number of seconds since UNIX Epoch, or any string compatible with `strtotime()`.
- * 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:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- *
- * See Also:
- * [REST Access Control Policy](http://docs.amazonwebservices.com/AmazonS3/latest/RESTAccessPolicy.html)
- */
- public function get_bucket_acl($bucket, $opt = null)
- {
- // Add this to our request
- if (!$opt) $opt = array();
- $opt['verb'] = 'GET';
- $opt['sub_resource'] = 'acl';
- // Authenticate to S3
- return $this->authenticate($bucket, $opt);
- }
- /**
- * Method: set_bucket_acl()
- * Sets the access control list (ACL) settings for the specified Amazon S3 bucket.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $acl - _string_ (Optional) The ACL settings for the specified bucket. [Allowed values: `AmazonS3::ACL_PRIVATE`, `AmazonS3::ACL_PUBLIC`, `AmazonS3::ACL_OPEN`, `AmazonS3::ACL_AUTH_READ`, `AmazonS3::ACL_OWNER_READ`, `AmazonS3::ACL_OWNER_FULL_CONTROL`]. Alternatively, an array of associative arrays. Each associative array contains an `id` and a `permission` key. The default value is <ACL_PRIVATE>.
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * 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:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- *
- * See Also:
- * [REST Access Control Policy](http://docs.amazonwebservices.com/AmazonS3/latest/RESTAccessPolicy.html)
- */
- public function set_bucket_acl($bucket, $acl = self::ACL_PRIVATE, $opt = null)
- {
- // Add this to our request
- if (!$opt) $opt = array();
- $opt['verb'] = 'PUT';
- $opt['sub_resource'] = 'acl';
- $opt['headers'] = array(
- 'Content-Type' => 'application/xml'
- );
- // Make sure these are defined.
- if (!defined('AWS_CANONICAL_ID') || !defined('AWS_CANONICAL_NAME'))
- {
- // Fetch the data live.
- $canonical = $this->get_canonical_user_id();
- define('AWS_CANONICAL_ID', $canonical['id']);
- define('AWS_CANONICAL_NAME', $canonical['display_name']);
- }
- if (is_array($acl))
- {
- $opt['body'] = $this->generate_access_policy(AWS_CANONICAL_ID, AWS_CANONICAL_NAME, $acl);
- }
- else
- {
- $opt['headers']['x-amz-acl'] = $acl;
- }
- // Authenticate to S3
- return $this->authenticate($bucket, $opt);
- }
- /*%******************************************************************************************%*/
- // OBJECT METHODS
- /**
- * Method: create_object()
- * Creates an Amazon S3 object. After an Amazon S3 bucket is created, objects can be stored in it.
- *
- * Each object can hold up to 5 GB of data. When an object is stored in Amazon S3, the data is streamed
- * to multiple storage servers in multiple data centers. This ensures the data remains available in the
- * event of internal network or hardware failure.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $filename - _string_ (Required) The file name for the object.
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * body - _string_ (Required; Conditional) The data to be stored in the object. Either this parameter or `fileUpload` must be specified.
- * fileUpload - _string_|_resource_ (Required; Conditional) The file system path for the local file to upload, or an open file resource. Either this parameter or `body` is required.
- * acl - _string_ (Optional) The ACL settings for the specified object. [Allowed values: `AmazonS3::ACL_PRIVATE`, `AmazonS3::ACL_PUBLIC`, `AmazonS3::ACL_OPEN`, `AmazonS3::ACL_AUTH_READ`, `AmazonS3::ACL_OWNER_READ`, `AmazonS3::ACL_OWNER_FULL_CONTROL`]. The default value is <ACL_PRIVATE>.
- * contentType - _string_ (Optional) The type of content that is being sent in the body. If a file is being uploaded via `fileUpload` as a file system path, it will attempt to determine the correct mime-type based on the file extension. The default value is `application/octet-stream`.
- * headers - _array_ (Optional) The standard HTTP headers to send along in the request.
- * meta - _array_ (Optional) An associative array of key-value pairs. Represented by `x-amz-meta-:` Any header starting with this prefix is considered user metadata. It will be stored with the object and returned when you retrieve the object. The total size of the HTTP request, not including the body, must be less than 4 KB.
- * storage - _string_ (Optional) Whether to use Standard or Reduced Redundancy storage. [Allowed values: `AmazonS3::STORAGE_STANDARD`, `AmazonS3::STORAGE_REDUCED`]. The default value is <STORAGE_STANDARD>.
- * 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:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- *
- * See Also:
- * [REST Access Control Policy](http://docs.amazonwebservices.com/AmazonS3/latest/RESTAccessPolicy.html)
- */
- public function create_object($bucket, $filename, $opt = null)
- {
- if (!$opt) $opt = array();
- // Add this to our request
- $opt['verb'] = 'PUT';
- $opt['resource'] = $filename;
- // Handle content type. Can also be passed as an HTTP header.
- if (isset($opt['contentType']))
- {
- $opt['headers']['Content-Type'] = $opt['contentType'];
- unset($opt['contentType']);
- }
- // Handle Access Control Lists. Can also be passed as an HTTP header.
- if (isset($opt['acl']))
- {
- $opt['headers']['x-amz-acl'] = $opt['acl'];
- unset($opt['acl']);
- }
- // Handle storage settings. Can also be passed as an HTTP header.
- if (isset($opt['storage']))
- {
- $opt['headers']['x-amz-storage-class'] = $opt['storage'];
- unset($opt['storage']);
- }
- // Handle meta tags. Can also be passed as an HTTP header.
- if (isset($opt['meta']))
- {
- foreach ($opt['meta'] as $meta_key => $meta_value)
- {
- // e.g., `My Meta Header` is converted to `x-amz-meta-my-meta-header`.
- $opt['headers']['x-amz-meta-' . strtolower(str_replace(' ', '-', $meta_key))] = $meta_value;
- }
- unset($opt['meta']);
- }
- // Authenticate to S3
- return $this->authenticate($bucket, $opt);
- }
- /**
- * Method: get_object()
- * Gets the contents of an Amazon S3 object in the specified bucket.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $filename - _string_ (Required) The file name for the object.
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * etag - _string_ (Optional) The `ETag` header passed in from a previous request. If specified, request `lastmodified` option must be specified as well. Will trigger a `304 Not Modified` status code if the file hasn't changed.
- * fileDownload - _string_|_resource_ (Optional) The file system location to download the file to, or an open file resource. Must be a server-writable location.
- * headers - _array_ (Optional) Standard HTTP headers to send along in the request.
- * lastmodified - _string_ (Optional) The `LastModified` header passed in from a previous request. If specified, request `etag` option must be specified as well. Will trigger a `304 Not Modified` status code if the file hasn't changed.
- * preauth - _integer_|_string_ (Optional) Specifies that a presigned URL for this request should be returned. May be passed as a number of seconds since UNIX Epoch, or any string compatible with `strtotime()`.
- * range - _string_ (Optional) The range of bytes to fetch from the object. Specify this parameter when downloading partial bits or completing incomplete object downloads. The specified range must be notated with a hyphen (e.g., 0-10485759). Defaults to the byte range of the complete Amazon S3 object.
- * versionId - _string_ (Optional) The version of the object to retrieve. Version IDs are returned in the `x-amz-version-id` header of any previous object-related request.
- * 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:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- */
- public function get_object($bucket, $filename, $opt = null)
- {
- if (!$opt) $opt = array();
- // Add this to our request
- $opt['verb'] = 'GET';
- $opt['resource'] = $filename;
- if (!isset($opt['headers']) || !is_array($opt['headers']))
- {
- $opt['headers'] = array();
- }
- // Are we checking for changes?
- if (isset($opt['lastmodified']) && isset($opt['etag']))
- {
- $opt['headers']['If-Modified-Since'] = $opt['lastmodified'];
- $opt['headers']['If-None-Match'] = $opt['etag'];
- }
- // Partial content range
- if (isset($opt['range']))
- {
- $opt['headers']['Range'] = 'bytes=' . $opt['range'];
- }
- // Authenticate to S3
- return $this->authenticate($bucket, $opt);
- }
- /**
- * Method: get_object_headers()
- * Gets the HTTP headers for the specified Amazon S3 object.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $filename - _string_ (Required) The file name for the object.
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * versionId - _string_ (Optional) The version of the object to retrieve. Version IDs are returned in the `x-amz-version-id` header of any previous object-related request.
- * preauth - _integer_|_string_ (Optional) Specifies that a presigned URL for this request should be returned. May be passed as a number of seconds since UNIX Epoch, or any string compatible with `strtotime()`.
- * 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:
- * _CFResponse_ A <CFResponse> object containing a parsed HTTP response.
- */
- public function get_object_headers($bucket, $filename, $opt = null)
- {
- // Add this to our request
- if (!$opt) $opt = array();
- $opt['verb'] = 'HEAD';
- $opt['resource'] = $filename;
- // Authenticate to S3
- return $this->authenticate($bucket, $opt);
- }
- /**
- * Method: delete_object()
- * Deletes an Amazon S3 object from the specified bucket.
- *
- * Access:
- * public
- *
- * Parameters:
- * $bucket - _string_ (Required) The name of the bucket to use.
- * $filename - _string_ (Required) The file name for the object.
- * $opt - _array_ (Optional) An associative array of parameters that can have the keys listed in the following section.
- *
- * Keys for the $opt parameter:
- * versionId - _string_ (Optional) The version of the object to delete. Version IDs are returned in the `x-amz-version-id` header of any previous object-related request.
- * 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_ (Opt…
Large files files are truncated, but you can click here to view the full file