/lib/aws/services/s3.class.php
PHP | 3639 lines | 1821 code | 463 blank | 1355 comment | 295 complexity | 96c14e0c753ef445895070abbb7c616e MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- * Copyright 2010-2011 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.
- */
- /*%******************************************************************************************%*/
- // EXCEPTIONS
- /**
- * Default S3 Exception.
- */
- class S3_Exception extends Exception {}
- /*%******************************************************************************************%*/
- // MAIN CLASS
- /**
- * 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 2011.12.02
- * @license See the included NOTICE.md file for more information.
- * @copyright See the included NOTICE.md file for more information.
- * @link http://aws.amazon.com/s3/ Amazon Simple Storage Service
- * @link http://aws.amazon.com/documentation/s3/ Amazon Simple Storage Service documentation
- */
- class AmazonS3 extends CFRuntime
- {
- /*%******************************************************************************************%*/
- // CLASS CONSTANTS
- /**
- * The default endpoint.
- */
- const DEFAULT_URL = 's3.amazonaws.com';
- /**
- * Specify the queue URL for the US-East (Northern Virginia) Region.
- */
- const REGION_US_E1 = '';
- /**
- * Specify the queue URL for the US-West (Northern California) Region.
- */
- const REGION_US_W1 = 'us-west-1';
- /**
- * Specify the queue URL for the US-West (Oregon) Region.
- */
- const REGION_US_W2 = 'us-west-2';
- /**
- * Specify the queue URL for the EU (Ireland) Region.
- */
- const REGION_EU_W1 = 'EU';
- /**
- * Specify the queue URL for the Asia Pacific (Singapore) Region.
- */
- const REGION_APAC_SE1 = 'ap-southeast-1';
- /**
- * Specify the queue URL for the Asia Pacific (Japan) Region.
- */
- const REGION_APAC_NE1 = 'ap-northeast-1';
- /**
- * ACL: Owner-only read/write.
- */
- const ACL_PRIVATE = 'private';
- /**
- * ACL: Owner read/write, public read.
- */
- const ACL_PUBLIC = 'public-read';
- /**
- * ACL: Public read/write.
- */
- const ACL_OPEN = 'public-read-write';
- /**
- * ACL: Owner read/write, authenticated read.
- */
- const ACL_AUTH_READ = 'authenticated-read';
- /**
- * ACL: Bucket owner read.
- */
- const ACL_OWNER_READ = 'bucket-owner-read';
- /**
- * ACL: Bucket owner full control.
- */
- const ACL_OWNER_FULL_CONTROL = 'bucket-owner-full-control';
- /**
- * 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';
- /**
- * 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';
- /**
- * 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';
- /**
- * 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';
- /**
- * 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';
- /**
- * The "AuthenticatedUsers" group for access control policies.
- */
- const USERS_AUTH = 'http://acs.amazonaws.com/groups/global/AuthenticatedUsers';
- /**
- * The "AllUsers" group for access control policies.
- */
- const USERS_ALL = 'http://acs.amazonaws.com/groups/global/AllUsers';
- /**
- * The "LogDelivery" group for access control policies.
- */
- const USERS_LOGGING = 'http://acs.amazonaws.com/groups/s3/LogDelivery';
- /**
- * PCRE: Match all items
- */
- const PCRE_ALL = '/.*/i';
- /**
- * Standard storage redundancy.
- */
- const STORAGE_STANDARD = 'STANDARD';
- /**
- * Reduced storage redundancy.
- */
- const STORAGE_REDUCED = 'REDUCED_REDUNDANCY';
- /*%******************************************************************************************%*/
- // PROPERTIES
- /**
- * The request URL.
- */
- public $request_url;
- /**
- * The virtual host setting.
- */
- public $vhost;
- /**
- * The base XML elements to use for access control policy methods.
- */
- public $base_acp_xml;
- /**
- * The base XML elements to use for creating buckets in regions.
- */
- public $base_location_constraint;
- /**
- * The base XML elements to use for logging methods.
- */
- public $base_logging_xml;
- /**
- * The base XML elements to use for notifications.
- */
- public $base_notification_xml;
- /**
- * The base XML elements to use for versioning.
- */
- public $base_versioning_xml;
- /**
- * The base XML elements to use for completing a multipart upload.
- */
- public $complete_mpu_xml;
- /**
- * The base XML elements to use for website support.
- */
- public $website_config_xml;
- /**
- * The DNS vs. Path-style setting.
- */
- public $path_style = false;
- /**
- * The state of whether the prefix change is temporary or permanent.
- */
- public $temporary_prefix = false;
- /**
- * The state of whether the response should be parsed or not.
- */
- public $parse_the_response = true;
- /*%******************************************************************************************%*/
- // CONSTRUCTOR
- /**
- * Constructs a new instance of <AmazonS3>. If the <code>AWS_DEFAULT_CACHE_CONFIG</code> configuration
- * option is set, requests will be authenticated using a session token. Otherwise, requests will use
- * the older authentication method.
- *
- * @param string $key (Optional) Your AWS key, or a session key. If blank, it will look for the <code>AWS_KEY</code> constant.
- * @param string $secret_key (Optional) Your AWS secret key, or a session secret key. If blank, it will look for the <code>AWS_SECRET_KEY</code> constant.
- * @param string $token (optional) An AWS session token. If blank, a request will be made to the AWS Secure Token Service to fetch a set of session credentials.
- * @return boolean A value of <code>false</code> if no valid values are set, otherwise <code>true</code>.
- */
- public function __construct($key = null, $secret_key = null, $token = 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/' . $this->api_version . '/"><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/' . $this->api_version . '/"></VersioningConfiguration>';
- $this->complete_mpu_xml = '<?xml version="1.0" encoding="utf-8"?><CompleteMultipartUpload></CompleteMultipartUpload>';
- $this->website_config_xml = '<?xml version="1.0" encoding="utf-8"?><WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/' . $this->api_version . '/"><IndexDocument><Suffix>index.html</Suffix></IndexDocument><ErrorDocument><Key>error.html</Key></ErrorDocument></WebsiteConfiguration>';
- $this->multi_object_delete_xml = '<?xml version="1.0" encoding="utf-8"?><Delete></Delete>';
- if (!$key && !defined('AWS_KEY'))
- {
- // @codeCoverageIgnoreStart
- throw new S3_Exception('No account key was passed into the constructor, nor was it set in the AWS_KEY constant.');
- // @codeCoverageIgnoreEnd
- }
- if (!$secret_key && !defined('AWS_SECRET_KEY'))
- {
- // @codeCoverageIgnoreStart
- throw new S3_Exception('No account secret was passed into the constructor, nor was it set in the AWS_SECRET_KEY constant.');
- // @codeCoverageIgnoreEnd
- }
- if (defined('AWS_DEFAULT_CACHE_CONFIG') && AWS_DEFAULT_CACHE_CONFIG)
- {
- return parent::session_based_auth($key, $secret_key, $token);
- }
- return parent::__construct($key, $secret_key, $token);
- }
- /*%******************************************************************************************%*/
- // AUTHENTICATION
- /**
- * Authenticates a connection to Amazon S3. Do not use directly unless implementing custom methods for
- * this class.
- *
- * @param string $bucket (Required) The name of the bucket to use.
- * @param array $opt (Optional) An associative array of parameters for authenticating. See the individual methods for allowed keys.
- * @param string $location (Do Not Use) Used internally by this function on occasions when Amazon S3 returns a redirect code and it needs to call itself recursively.
- * @param integer $redirects (Do Not Use) Used internally by this function on occasions when Amazon S3 returns a redirect code and it needs to call itself recursively.
- * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
- * @link http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3_Authentication.html REST authentication
- */
- 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, response-* ##
- * 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 ##
- * 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))
- {
- // @codeCoverageIgnoreStart
- 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.');
- // @codeCoverageIgnoreEnd
- }
- // 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);
- if ($this->parse_the_response)
- {
- // 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))
- {
- // Fall back to the older path-style URI
- $this->set_resource_prefix('/' . $bucket);
- $this->temporary_prefix = true;
- }
- elseif ($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(CFUtilities::DATE_FORMAT_RFC2616, (time() + (integer) $this->adjust_offset));
- // Storage for request parameters.
- $resource = '';
- $sub_resource = '';
- $querystringparams = array();
- $signable_querystringparams = array();
- $string_to_sign = '';
- $headers = array(
- 'Content-MD5' => '',
- 'Content-Type' => 'application/x-www-form-urlencoded',
- 'Date' => $date
- );
- /*%******************************************************************************************%*/
- // Do we have an authentication token?
- if ($this->auth_token)
- {
- $headers['X-Amz-Security-Token'] = $this->auth_token;
- }
- // Handle specific resources
- if (isset($opt['resource']))
- {
- $resource .= $opt['resource'];
- }
- // Merge query string values
- if (isset($opt['query_string']))
- {
- $querystringparams = array_merge($querystringparams, $opt['query_string']);
- }
- $query_string = $this->util->to_query_string($querystringparams);
- // Merge the signable query string values. Must be alphabetical.
- $signable_list = array(
- 'partNumber',
- 'response-cache-control',
- 'response-content-disposition',
- 'response-content-encoding',
- 'response-content-language',
- 'response-content-type',
- 'response-expires',
- 'uploadId',
- 'versionId'
- );
- foreach ($signable_list as $item)
- {
- if (isset($opt[$item]))
- {
- $signable_querystringparams[$item] = $opt[$item];
- }
- }
- $signable_query_string = $this->util->to_query_string($signable_querystringparams);
- // Merge the HTTP headers
- if (isset($opt['headers']))
- {
- $headers = array_merge($headers, $opt['headers']);
- }
- // Compile the URI to request
- $conjunction = '?';
- $signable_resource = '/' . str_replace('%2F', '/', rawurlencode($resource));
- $non_signable_resource = '';
- if (isset($opt['sub_resource']))
- {
- $signable_resource .= $conjunction . rawurlencode($opt['sub_resource']);
- $conjunction = '&';
- }
- if ($signable_query_string !== '')
- {
- $signable_query_string = $conjunction . $signable_query_string;
- $conjunction = '&';
- }
- if ($query_string !== '')
- {
- $non_signable_resource .= $conjunction . $query_string;
- $conjunction = '&';
- }
- $this->request_url = $scheme . $hostname . $signable_resource . $signable_query_string . $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;
- // Pass along registered stream callbacks
- if ($this->registered_streaming_read_callback)
- {
- $request->register_streaming_read_callback($this->registered_streaming_read_callback);
- }
- if ($this->registered_streaming_write_callback)
- {
- $request->register_streaming_write_callback($this->registered_streaming_write_callback);
- }
- // Streaming uploads
- if (isset($opt['fileUpload']))
- {
- if (is_resource($opt['fileUpload']))
- {
- // Determine the length to read from the stream
- $length = null; // From current position until EOF by default, size determined by set_read_stream()
- if (isset($headers['Content-Length']))
- {
- $length = $headers['Content-Length'];
- }
- elseif (isset($opt['seekTo']))
- {
- // Read from seekTo until EOF by default
- $stats = fstat($opt['fileUpload']);
- if ($stats && $stats['size'] >= 0)
- {
- $length = $stats['size'] - (integer) $opt['seekTo'];
- }
- }
- $request->set_read_stream($opt['fileUpload'], $length);
- if ($headers['Content-Type'] === 'application/x-www-form-urlencoded')
- {
- $headers['Content-Type'] = 'application/octet-stream';
- }
- }
- else
- {
- $request->set_read_file($opt['fileUpload']);
- // Determine the length to read from the file
- $length = $request->read_stream_size; // The file size by default
- if (isset($headers['Content-Length']))
- {
- $length = $headers['Content-Length'];
- }
- elseif (isset($opt['seekTo']) && isset($length))
- {
- // Read from seekTo until EOF by default
- $length -= (integer) $opt['seekTo'];
- }
- $request->set_read_stream_size($length);
- // 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;
- $headers['Content-MD5'] = '';
- }
- // Handle streaming file offsets
- if (isset($opt['seekTo']))
- {
- // Pass the seek position to RequestCore
- $request->set_seek_position((integer) $opt['seekTo']);
- }
- // 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;
- }
- // 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'] = is_int($opt['preauth']) ? $opt['preauth'] : 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 . urldecode($signable_query_string);
- // 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 . $conjunction . 'AWSAccessKeyId=' . $this->key . '&Expires=' . $headers['Expires'] . '&Signature=' . rawurlencode($signature);
- }
- elseif (isset($opt['preauth']))
- {
- return $this->request_url;
- }
- /*%******************************************************************************************%*/
- // If our changes were temporary, reset them.
- if ($this->temporary_prefix)
- {
- $this->temporary_prefix = false;
- $this->resource_prefix = null;
- }
- // 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/dev/Redirects.html
- // @codeCoverageIgnoreStart
- 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);
- }
- }
- // @codeCoverageIgnoreEnd
- // Return!
- return $data;
- }
- /**
- * 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.
- *
- * @param string $bucket (Required) The name of the bucket to validate.
- * @return boolean Whether or not the specified Amazon S3 bucket name is valid for DNS-style access. A value of <code>true</code> means that the bucket name is valid. A value of <code>false</code> 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;
- }
- /**
- * 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.
- *
- * @param string $bucket (Required) The name of the bucket to validate.
- * @return boolean Whether or not the bucket name is valid. A value of <code>true</code> means that the bucket name is valid. A value of <code>false</code> 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;
- }
- /**
- * 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.
- *
- * @param string $bucket (Required) The name of the bucket to use.
- * @param array $opt (Optional) An associative array of parameters for authenticating. See the individual methods for allowed keys.
- * @param string $location (Optional) Used internally by this method when Amazon S3 returns a redirect code and needs to call itself recursively.
- * @param integer $redirects (Optional) Used internally by this method when Amazon S3 returns a redirect code and needs to call itself recursively.
- * @return 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
- /**
- * Sets the region to use for subsequent Amazon S3 operations. This will also reset any prior use of
- * <enable_path_style()>.
- *
- * @param string $region (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`, `AmazonS3::REGION_APAC_NE1`]
- * @return $this A reference to the current instance.
- */
- public function set_region($region)
- {
- switch ($region)
- {
- case self::REGION_US_E1: // Northern Virginia
- $this->set_hostname(self::DEFAULT_URL);
- $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;
- case self::REGION_US_W1: // Northern California
- case self::REGION_APAC_SE1: // Singapore
- case self::REGION_APAC_NE1: // Japan
- default:
- $this->set_hostname('s3-' . $region . '.amazonaws.com');
- $this->enable_path_style(false);
- break;
- // @codeCoverageIgnoreStart
- }
- // @codeCoverageIgnoreEnd
- return $this;
- }
- /**
- * Sets the virtual host to use in place of the default `bucket.s3.amazonaws.com` domain.
- *
- * @param string $vhost (Required) The virtual host to use in place of the default `bucket.s3.amazonaws.com` domain.
- * @return $this A reference to the current instance.
- * @link http://docs.amazonwebservices.com/AmazonS3/latest/dev/VirtualHosting.html Virtual Hosting of Buckets
- */
- public function set_vhost($vhost)
- {
- $this->vhost = $vhost;
- return $this;
- }
- /**
- * Enables the use of the older path-style URI access for all requests.
- *
- * @param string $style (Optional) Whether or not to enable path-style URI access for all requests. The default value is <code>true</code>.
- * @return $this A reference to the current instance.
- */
- public function enable_path_style($style = true)
- {
- $this->path_style = $style;
- return $this;
- }
- /*%******************************************************************************************%*/
- // BUCKET METHODS
- /**
- * 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.
- *
- * @param string $bucket (Required) The name of the bucket to create.
- * @param string $region (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`, `AmazonS3::REGION_APAC_NE1`]
- * @param string $acl (Optional) The ACL settings for the specified bucket. [Allowed values: <code>AmazonS3::ACL_PRIVATE</code>, <code>AmazonS3::ACL_PUBLIC</code>, <code>AmazonS3::ACL_OPEN</code>, <code>AmazonS3::ACL_AUTH_READ</code>, <code>AmazonS3::ACL_OWNER_READ</code>, <code>AmazonS3::ACL_OWNER_FULL_CONTROL</code>]. The default value is <ACL_PRIVATE>.
- * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
- * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
- * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request.</li></ul>
- * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
- * @link http://docs.amazonwebservices.com/AmazonS3/latest/dev/UsingBucket.html Working with Amazon S3 Buckets
- */
- 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))
- {
- // @codeCoverageIgnoreStart
- 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.');
- // @codeCoverageIgnoreEnd
- }
- 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_E1: // Northern Virginia
- $opt['body'] = '';
- 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;
- case self::REGION_US_W1: // Northern California
- case self::REGION_APAC_SE1: // Singapore
- case self::REGION_APAC_NE1: // Japan
- default:
- $xml->LocationConstraint = $region;
- $opt['body'] = $xml->asXML();
- break;
- // @codeCoverageIgnoreStart
- }
- // @codeCoverageIgnoreEnd
- $response = $this->authenticate($bucket, $opt);
- return $response;
- }
- /**
- * Gets the region in which the specified Amazon S3 bucket is located.
- *
- * @param string $bucket (Required) The name of the bucket to use.
- * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
- * <li><code>preauth</code> - <code>integer|string</code> - 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 <php:strtotime()>.</li>
- * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
- * @return 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;
- }
- /**
- * Gets the HTTP headers for the specified Amazon S3 bucket.
- *
- * @param string $bucket (Required) The name of the bucket to use.
- * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
- * <li><code>preauth</code> - <code>integer|string</code> - 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 <php:strtotime()>.</li>
- * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
- * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
- * @return 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);
- }
- /**
- * Deletes a bucket from an Amazon S3 account. A bucket must be empty before the bucket itself can be deleted.
- *
- * @param string $bucket (Required) The name of the bucket to use.
- * @param boolean $force (Optional) Whether to force-delete the bucket and all of its contents. The default value is <code>false</code>.
- * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
- * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
- * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
- * @return mixed A <CFResponse> object if the bucket was deleted successfully. Returns boolean <code>false</code> 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);
- }
- // @codeCoverageIgnoreStart
- return false;
- // @codeCoverageIgnoreEnd
- }
- /**
- * Gets a list of all buckets contained in the caller's Amazon S3 account.
- *
- * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
- * <li><code>preauth</code> - <code>integer|string</code> - 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 <php:strtotime()>.</li>
- * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
- * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
- * @return 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);
- }
- /**
- * Gets the access control list (ACL) settings for the specified Amazon S3 bucket.
- *
- * @param string $bucket (Required) The name of the bucket to use.
- * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
- * <li><code>preauth</code> - <code>integer|string</code> - 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 <php:strtotime()>.</li>
- * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
- * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
- * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
- * @link http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAccessPolicy.html REST Access Control Policy
- */
- 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);
- }
- /**
- * Sets the access control list (ACL) settings for the specified Amazon S3 bucket.
- *
- * @param string $bucket (Required) The name of the bucket to use.
- * @param string $acl (Optional) The ACL settings for the specified bucket. [Allowed values: <code>AmazonS3::ACL_PRIVATE</code>, <code>AmazonS3::ACL_PUBLIC</code>, <code>AmazonS3::ACL_OPEN</code>, <code>AmazonS3::ACL_AUTH_READ</code>, <code>AmazonS3::ACL_OWNER_READ</code>, <code>AmazonS3::ACL_OWNER_FULL_CONTROL</code>]. Alternatively, an array of associative arrays. Each associative array contains an `id` and a `permission` key. The default value is <ACL_PRIVATE>.
- * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
- * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
- * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
- * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
- * @link http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAccessPolicy.html REST Access Control Policy
- */
- 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.
- // @codeCoverageIgnoreStart
- 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']);
- }
- // @codeCoverageIgnoreEnd
- if (is_array($acl))
- {
- $opt['body'] = $this->generate_access_policy(AWS_CANONICAL_ID, AWS_CANONICAL_NAME, $acl);
- }
- else
- {
- $opt['body'] = '';
- $opt['headers']['x-amz-acl'] = $acl;
- }
- // Authenticate to S3
- return $this->authenticate($bucket, $opt);
- }
- /*%******************************************************************************************%*/
- // OBJECT METHODS
- /**
- * Creates an Amazon S3 object. After an Amazon S3 bucket is created, objects can be stored in it.
- *
- * Each standard 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.
- *
- * @param string $bucket (Required) The name of the bucket to use.
- * @param string $filename (Required) The file name for the object.
- * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
- * <li><code>body</code> - <code>string</code> - Required; Conditional - The data to be stored in the object. Either this parameter or <code>fileUpload</code> must be specified.</li>
- * <li><code>fileUpload</code> - <code>string|resource</code> - Required; Conditional - The URL/path for the file to upload, or an open resource. Either this parameter or <code>body</code> is required.</li>
- * <li><code>acl</code> - <code>string</code> - Optional - The ACL settings for the specified object. [Allowed values: <code>AmazonS3::ACL_PRIVATE</code>, <code>AmazonS3::ACL_PUBLIC</code>, <code>AmazonS3::ACL_OPEN</code>, <code>AmazonS3::ACL_AUTH_READ</code>, <code>AmazonS3::ACL_OWNER_READ</code>, <code>AmazonS3::ACL_OWNER_FULL_CONTROL</code>]. The default value is <code>ACL_PRIVATE</code>.</li>
- * <li><code>contentType</code> - <code>string</code> - Optional - The type of content that is being sent in the body. If a file is being uploaded via <code>fileUpload</code> as a file system path, it will attempt to determine the correct mime-type based on the file extension. The default value is <code>application/octet-stream</code>.</li>
- * <li><code>contentType</code> - <code>string</code> - Optional - The type of content that is being sent in the body. If a file is being uploaded via <code>fileUpload</code> as a file system path, it will attempt to determine the correct mime-type based on the file extension. The default value is <code>application/octet-stream</code>.</li>
- * <li><code>encryption</code> - <code>string</code> - Optional - The algorithm to use for encrypting the object. [Allowed values: <code>AES256</code>]</li>
- * <li><code>headers</code> - <code>array</code> - Optional - The standard HTTP headers to send along in the request.</li>
- * <li><code>length</code> - <code>integer</code> - Optional - The size of the object in bytes. For more information, see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13">RFC 2616, section 14.13</a>. The value can also be passed to the <code>header</code> option as <code>Content-Length</code>.</li>
- * <li><code>meta</code> - <code>array</code> - Optional - An associative array of key-value pairs. Represented by <code>x-amz-meta-:</code>. 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.</li>
- * <li><code>seekTo</code> - <code>integer</code> - Optional - The starting position in bytes within the file/stream to upload from.</li>
- * <li><code>storage</code> - <code>string</code> - Optional - Whether to use Standard or Reduced Redundancy storage. [Allowed values: <code>AmazonS3::STORAGE_STANDARD</code>, <code>AmazonS3::STORAGE_REDUCED</code>]. The default value is <code>STORAGE_STANDARD</code>.</li>
- * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
- * <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
- * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
- * @link http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAccessPolicy.html REST Access Control Policy
- */
- 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 length. Can also be passed as an HTTP header.
- if (isset($opt['length']))
- {
- $opt['headers']['Content-Length'] = $opt['length'];
- unset($opt['length']);
- }
- // 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 encryption settings. Can also be passed as an HTTP header.
- if (isset($opt['encryption']))
- {
- $opt['headers']['x-amz-server-side-encryption'] = $opt['encryption'];
- unset($opt['encryption']);
- }
- // 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);
- }
- /**
- * Gets the contents of an Amazon S3 object in the specified bucket.
- *
- * @param string $bucket (Required) The name of the bucket to use.
- * @param string $filename (Required) The file name for the object.
- * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
- * <li…
Large files files are truncated, but you can click here to view the full file