Amazon S3 PHP connection class

category Zend
package Zend_Service
subpackage Amazon_S3
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License
see
inherited_from \Zend_Service_Amazon_Abstract

 Methods

Constructor

__construct(string $accessKey = null, string $secretKey = null, string $region = null
inherited_from \Zend_Service_Amazon_Abstract::__construct()

Parameters

$accessKey

string

$secretKey

string

$region

string

Create Amazon client.

__construct($accessKey = null, $secretKey = null) : void
Inherited

Parameters

$accessKey

$secretKey

Make a request to Amazon S3

_makeRequest(string $method, string $path = '', array $params = null, array $headers = array(), string|resource $data = null) : \Zend_Http_Response

Parameters

$method

string

Request method

$path

string

Path to requested object

$params

array

Request parameters

$headers

array

HTTP headers

$data

stringresource

Request data

Returns

\Zend_Http_Response

Verify if the bucket name is valid

_validBucketName(string $bucket) : boolean

Parameters

$bucket

string

Returns

boolean

Remove all objects in the bucket.

cleanBucket(string $bucket) : boolean

Parameters

$bucket

string

Returns

boolean

Copy an object

copyObject(string $sourceObject, string $destObject, array $meta = null) : boolean

Parameters

$sourceObject

string

Source object name

$destObject

string

Destination object name

$meta

array

(OPTIONAL) Metadata to apply to desination object. Set to null to copy metadata from source object.

Returns

boolean

Add a new bucket

createBucket(string $bucket, $location = null) : boolean

Parameters

$bucket

string

$location

Returns

boolean

List the S3 buckets

getBuckets() : array | false

Returns

arrayfalse

Get current S3 endpoint

getEndpoint() : \Zend_Uri_Http

Returns

\Zend_Uri_Http

Gets the HTTP client object.

getHttpClient() : \Zend_Http_Client
InheritedStatic

Returns

\Zend_Http_Client

Get metadata information for a given object

getInfo(string $object) : array | false

Parameters

$object

string

Returns

arrayfalse

Attempt to get the content-type of a file based on the extension

getMimeType(string $path) : string
Static

Parameters

$path

string

Returns

string

Get an object

getObject(string $object, boolean $paidobject = false) : string | false

Parameters

$object

string

$paidobject

boolean

This is "requestor pays" object

Returns

stringfalse

Get an object using streaming

getObjectStream(string $object, string $streamfile = null, boolean $paidobject = false) : \Zend_Http_Response_Stream | false

Can use either provided filename for storage or create a temp file if none provided.

Parameters

$object

string

Object path

$streamfile

string

File to write the stream to

$paidobject

boolean

This is "requestor pays" object

Returns

\Zend_Http_Response_Streamfalse

List the objects and common prefixes in a bucket.

getObjectsAndPrefixesByBucket(string $bucket, array $params = array()) : array | false

Provides the list of object keys and common prefixes that are contained in the bucket. Valid params include the following. prefix - Limits the response to keys which begin with the indicated prefix. You can use prefixes to separate a bucket into different sets of keys in a way similar to how a file system uses folders. marker - Indicates where in the bucket to begin listing. The list will only include keys that occur lexicographically after marker. This is convenient for pagination: To get the next page of results use the last key of the current page as the marker. max-keys - The maximum number of keys you'd like to see in the response body. The server might return fewer than this many keys, but will not return more. delimiter - Causes keys that contain the same string between the prefix and the first occurrence of the delimiter to be rolled up into a single result element in the CommonPrefixes collection. These rolled-up keys are not returned elsewhere in the response.

see

Parameters

$bucket

string

$params

array

S3 GET Bucket Paramater

Returns

arrayfalse

List the objects in a bucket.

getObjectsByBucket(string $bucket, array $params = array()) : array | false

Provides the list of object keys that are contained in the bucket. Valid params include the following. prefix - Limits the response to keys which begin with the indicated prefix. You can use prefixes to separate a bucket into different sets of keys in a way similar to how a file system uses folders. marker - Indicates where in the bucket to begin listing. The list will only include keys that occur lexicographically after marker. This is convenient for pagination: To get the next page of results use the last key of the current page as the marker. max-keys - The maximum number of keys you'd like to see in the response body. The server might return fewer than this many keys, but will not return more. delimiter - Causes keys that contain the same string between the prefix and the first occurrence of the delimiter to be rolled up into a single result element in the CommonPrefixes collection. These rolled-up keys are not returned elsewhere in the response.

Parameters

$bucket

string

$params

array

S3 GET Bucket Paramater

Returns

arrayfalse

Get wrapper client for stream type

getWrapperClient(string $name) : \Zend_Service_Amazon_S3
Static

Parameters

$name

string

Returns

\Zend_Service_Amazon_S3

Checks if a given bucket name is available

isBucketAvailable(string $bucket) : boolean

Parameters

$bucket

string

Returns

boolean

Checks if a given object exists

isObjectAvailable(string $object) : boolean

Parameters

$object

string

Returns

boolean

Move an object

moveObject(string $sourceObject, string $destObject, array $meta = null

Performs a copy to dest + verify + remove source

Parameters

$sourceObject

string

Source object name

$destObject

string

Destination object name

$meta

array

(OPTIONAL) Metadata to apply to destination object. Set to null to retain existing metadata.

Put file to S3 as object

putFile(string $path, string $object, array $meta = null) : boolean

Parameters

$path

string

File name

$object

string

Object name

$meta

array

Metadata

Returns

boolean

Put file to S3 as object, using streaming

putFileStream(string $path, string $object, array $meta = null) : boolean

Parameters

$path

string

File name

$object

string

Object name

$meta

array

Metadata

Returns

boolean

Upload an object by a PHP string

putObject(string $object, string|resource $data, array $meta = null) : boolean

Parameters

$object

string

Object name

$data

stringresource

Object data (can be string or stream)

$meta

array

Metadata

Returns

boolean

Register this object as stream wrapper client

registerAsClient(string $name) : \Zend_Service_Amazon_S3

Parameters

$name

string

Returns

\Zend_Service_Amazon_S3

Register this object as stream wrapper

registerStreamWrapper(string $name = 's3') : \Zend_Service_Amazon_S3

Parameters

$name

string

Returns

\Zend_Service_Amazon_S3

Remove a given bucket. All objects in the bucket must be removed prior to removing the bucket.

removeBucket(string $bucket) : boolean

Parameters

$bucket

string

Returns

boolean

Remove a given object

removeObject(string $object) : boolean

Parameters

$object

string

Returns

boolean

Set S3 endpoint to use

setEndpoint(string|\Zend_Uri_Http $endpoint) : \Zend_Service_Amazon_S3

Parameters

$endpoint

string\Zend_Uri_Http

Returns

\Zend_Service_Amazon_S3

Sets the HTTP client object to use for retrieving the feeds. If none is set, the default Zend_Http_Client will be used.

setHttpClient(\Zend_Http_Client $httpClient) 
InheritedStatic

Parameters

$httpClient

\Zend_Http_Client

Set the keys to use when accessing SQS.

setKeys($accessKey, $secretKey) : void
InheritedStatic

Parameters

$accessKey

$secretKey

Unregister this object as stream wrapper client

unregisterAsClient(string $name) : \Zend_Service_Amazon_S3

Parameters

$name

string

Returns

\Zend_Service_Amazon_S3

Unregister this object as stream wrapper

unregisterStreamWrapper(string $name = 's3') : \Zend_Service_Amazon_S3

Parameters

$name

string

Returns

\Zend_Service_Amazon_S3

Make sure the object name is valid

_fixupObjectName(string $object) : string

Parameters

$object

string

Returns

string

Method to fetch the Access Key

_getAccessKey() : string
Inherited

Returns

string

Method to fetch the Secret AWS Key

_getSecretKey() : string
Inherited

Returns

string

Add the S3 Authorization signature to the request headers

addSignature(string $method, string $path, $headers) : string

Parameters

$method

string

$path

string

$headers

Returns

string

 Properties

 

Amazon Access Key

$_accessKey : string

Default

 

Amazon Access Key

$_defaultAccessKey : string

Default

null
Static
 

Amazon Secret Key

$_defaultSecretKey : string

Default

null
Static
 

Endpoint for the service

$_endpoint : \Zend_Uri_Http

Default

 

HTTP Client used to query all web services

$_httpClient : \Zend_Http_Client

Default

null
Static
 

Amazon Secret Key

$_secretKey : string

Default

 

Store for stream wrapper clients

$_wrapperClients : array

Default

array()
Static

 Constants

 

S3_ACL_AUTH_READ

S3_ACL_AUTH_READ = 'authenticated-read' 
 

S3_ACL_HEADER

S3_ACL_HEADER = 'x-amz-acl' 
 

S3_ACL_PRIVATE

S3_ACL_PRIVATE = 'private' 
 

S3_ACL_PUBLIC_READ

S3_ACL_PUBLIC_READ = 'public-read' 
 

S3_ACL_PUBLIC_WRITE

S3_ACL_PUBLIC_WRITE = 'public-read-write' 
 

S3_CONTENT_TYPE_HEADER

S3_CONTENT_TYPE_HEADER = 'Content-Type' 
 

S3_ENDPOINT

S3_ENDPOINT = 's3.amazonaws.com' 
 

S3_REQUESTPAY_HEADER

S3_REQUESTPAY_HEADER = 'x-amz-request-payer'