S3Wrapper
extends S3
in package
Amazon S3 PHP class
Table of Contents
Constants
- ACL_AUTHENTICATED_READ = 'authenticated-read'
- ACL_PRIVATE = 'private'
- ACL_PUBLIC_READ = 'public-read'
- ACL_PUBLIC_READ_WRITE = 'public-read-write'
- SSE_AES256 = 'AES256'
- SSE_NONE = ''
- STORAGE_CLASS_RRS = 'REDUCED_REDUNDANCY'
- STORAGE_CLASS_STANDARD = 'STANDARD'
- STORAGE_CLASS_STANDARD_IA = 'STANDARD_IA'
Properties
- $defDelimiter : string
- Default delimiter to be used, for example while getBucket().
- $endpoint : string
- AWS URI
- $proxy : null|array<string|int, mixed>
- Proxy information
- $signVer : string
- AWS Signature Version
- $sslCACert : string
- SSL CA cert (only required if you are having problems with your system CA cert)
- $sslCert : string
- SSL client certfificate
- $sslKey : bool
- SSL client key
- $useExceptions : bool
- Use PHP exceptions?
- $useSSL : bool
- Connect using SSL?
- $useSSLValidation : bool
- Use SSL validation?
- $useSSLVersion : const
- Use SSL version
- $buffer : mixed
- $mode : mixed
- $position : mixed
Methods
- __construct() : void
- Constructor - if you're not using the class statically
- copyObject() : mixed|false
- Copy an object
- createDistribution() : array<string|int, mixed>|false
- Create a CloudFront distribution
- deleteBucket() : bool
- Delete an empty bucket
- deleteDistribution() : bool
- Delete a CloudFront distribution
- deleteObject() : bool
- Delete an object
- dir_closedir() : mixed
- dir_opendir() : mixed
- dir_readdir() : mixed
- dir_rewinddir() : mixed
- disableBucketLogging() : bool
- Disable bucket logging
- freeSigningKey() : void
- Free signing key from memory, MUST be called if you are using setSigningKey()
- getAccessControlPolicy() : mixed|false
- Get object or bucket Access Control Policy
- getAuthenticatedURL() : string
- Get a query string authenticated URL
- getBucket() : array<string|int, mixed>|false
- Get contents for a bucket
- getBucketLocation() : string|false
- Get a bucket's location
- getBucketLogging() : array<string|int, mixed>|false
- Get logging status for a bucket
- getDistribution() : array<string|int, mixed>|false
- Get CloudFront distribution info
- getDistributionInvalidationList() : array<string|int, mixed>
- List your invalidation batches for invalidateDistribution() in a CloudFront distribution
- getHttpUploadPostParams() : object
- Get upload POST parameters for form uploads
- getObject() : mixed
- Get an object
- getObjectInfo() : mixed|false
- Get object information
- getSignedCannedURL() : string
- Get a CloudFront canned policy URL
- getSignedPolicyURL() : string
- Get a CloudFront signed policy URL
- hasAuth() : bool
- Check if AWS keys have been set
- inputFile() : array<string|int, mixed>|false
- Create input info array for putObject()
- inputResource() : array<string|int, mixed>|false
- Create input array info for putObject() with a resource
- invalidateDistribution() : bool
- Invalidate objects in a CloudFront distribution
- listBuckets() : array<string|int, mixed>|false
- Get a list of buckets
- listDistributions() : array<string|int, mixed>
- Get a list of CloudFront distributions
- listOriginAccessIdentities() : array<string|int, mixed>
- List CloudFront Origin Access Identities
- mkdir() : mixed
- putBucket() : bool
- Put a bucket
- putObject() : bool
- Put an object
- putObjectFile() : bool
- Put an object from a file (legacy function)
- putObjectString() : bool
- Put an object from a string (legacy function)
- rmdir() : mixed
- setAccessControlPolicy() : bool
- Set object or bucket Access Control Policy
- setAuth() : void
- Set AWS access key and secret key
- setBucketLogging() : bool
- Set logging for a bucket
- setBucketRedirect() : bool
- Set up a bucket redirection
- setEndpoint() : void
- Set the service endpoint
- setExceptions() : void
- Set the error mode to exceptions
- setProxy() : void
- Set proxy information
- setSignatureVersion() : void
- Set Signature Version
- setSigningKey() : bool
- Set signing key
- setSSL() : void
- Set SSL on or off
- setSSLAuth() : void
- Set SSL client certificates (experimental)
- setTimeCorrectionOffset() : void
- Set AWS time correction offset (use carefully)
- stream_close() : mixed
- stream_eof() : mixed
- stream_flush() : mixed
- stream_open() : mixed
- stream_read() : mixed
- stream_seek() : mixed
- stream_stat() : mixed
- stream_tell() : mixed
- stream_write() : mixed
- unlink() : mixed
- updateDistribution() : array<string|int, mixed>|false
- Update a CloudFront distribution
- url_stat() : mixed
- __getURL() : mixed
- __translateMode() : mixed
Constants
ACL_AUTHENTICATED_READ
public
mixed
ACL_AUTHENTICATED_READ
= 'authenticated-read'
ACL_PRIVATE
public
mixed
ACL_PRIVATE
= 'private'
ACL_PUBLIC_READ
public
mixed
ACL_PUBLIC_READ
= 'public-read'
ACL_PUBLIC_READ_WRITE
public
mixed
ACL_PUBLIC_READ_WRITE
= 'public-read-write'
SSE_AES256
public
mixed
SSE_AES256
= 'AES256'
SSE_NONE
public
mixed
SSE_NONE
= ''
STORAGE_CLASS_RRS
public
mixed
STORAGE_CLASS_RRS
= 'REDUCED_REDUNDANCY'
STORAGE_CLASS_STANDARD
public
mixed
STORAGE_CLASS_STANDARD
= 'STANDARD'
STORAGE_CLASS_STANDARD_IA
public
mixed
STORAGE_CLASS_STANDARD_IA
= 'STANDARD_IA'
Properties
$defDelimiter
Default delimiter to be used, for example while getBucket().
public
static string
$defDelimiter
= \null
Tags
$endpoint
AWS URI
public
static string
$endpoint
= 's3.amazonaws.com'
Tags
$proxy
Proxy information
public
static null|array<string|int, mixed>
$proxy
= \null
Tags
$signVer
AWS Signature Version
public
static string
$signVer
= 'v2'
Tags
$sslCACert
SSL CA cert (only required if you are having problems with your system CA cert)
public
static string
$sslCACert
= \null
Tags
$sslCert
SSL client certfificate
public
static string
$sslCert
= \null
Tags
$sslKey
SSL client key
public
static bool
$sslKey
= \null
Tags
$useExceptions
Use PHP exceptions?
public
static bool
$useExceptions
= \false
Tags
$useSSL
Connect using SSL?
public
static bool
$useSSL
= \false
Tags
$useSSLValidation
Use SSL validation?
public
static bool
$useSSLValidation
= \true
Tags
$useSSLVersion
Use SSL version
public
static const
$useSSLVersion
= \CURL_SSLVERSION_TLSv1
Tags
$buffer
private
mixed
$buffer
$mode
private
mixed
$mode
= ''
$position
private
mixed
$position
= 0
Methods
__construct()
Constructor - if you're not using the class statically
public
__construct([string $accessKey = null ][, string $secretKey = null ][, bool $useSSL = false ][, string $endpoint = 's3.us-east-2.amazonaws.com' ]) : void
Parameters
- $accessKey : string = null
-
Access key
- $secretKey : string = null
-
Secret key
- $useSSL : bool = false
-
Enable SSL
- $endpoint : string = 's3.us-east-2.amazonaws.com'
-
Amazon URI
copyObject()
Copy an object
public
static copyObject(string $srcBucket, string $srcUri, string $bucket, string $uri[, constant $acl = self::ACL_PRIVATE ][, array<string|int, mixed> $metaHeaders = array() ][, array<string|int, mixed> $requestHeaders = array() ][, constant $storageClass = self::STORAGE_CLASS_STANDARD ]) : mixed|false
Parameters
- $srcBucket : string
-
Source bucket name
- $srcUri : string
-
Source object URI
- $bucket : string
-
Destination bucket name
- $uri : string
-
Destination object URI
- $acl : constant = self::ACL_PRIVATE
-
ACL constant
- $metaHeaders : array<string|int, mixed> = array()
-
Optional array of x-amz-meta-* headers
- $requestHeaders : array<string|int, mixed> = array()
-
Optional array of request headers (content type, disposition, etc.)
- $storageClass : constant = self::STORAGE_CLASS_STANDARD
-
Storage class constant
Return values
mixed|falsecreateDistribution()
Create a CloudFront distribution
public
static createDistribution(string $bucket[, bool $enabled = true ][, array<string|int, mixed> $cnames = array() ][, string $comment = null ][, string $defaultRootObject = null ][, string $originAccessIdentity = null ][, array<string|int, mixed> $trustedSigners = array() ]) : array<string|int, mixed>|false
Parameters
- $bucket : string
-
Bucket name
- $enabled : bool = true
-
Enabled (true/false)
- $cnames : array<string|int, mixed> = array()
-
Array containing CNAME aliases
- $comment : string = null
-
Use the bucket name as the hostname
- $defaultRootObject : string = null
-
Default root object
- $originAccessIdentity : string = null
-
Origin access identity
- $trustedSigners : array<string|int, mixed> = array()
-
Array of trusted signers
Return values
array<string|int, mixed>|falsedeleteBucket()
Delete an empty bucket
public
static deleteBucket(string $bucket) : bool
Parameters
- $bucket : string
-
Bucket name
Return values
booldeleteDistribution()
Delete a CloudFront distribution
public
static deleteDistribution(array<string|int, mixed> $dist) : bool
Parameters
- $dist : array<string|int, mixed>
-
Distribution array info identical to output of getDistribution()
Return values
booldeleteObject()
Delete an object
public
static deleteObject(string $bucket, string $uri) : bool
Parameters
- $bucket : string
-
Bucket name
- $uri : string
-
Object URI
Return values
booldir_closedir()
public
dir_closedir() : mixed
dir_opendir()
public
dir_opendir(mixed $path, mixed $options) : mixed
Parameters
- $path : mixed
- $options : mixed
dir_readdir()
public
dir_readdir() : mixed
dir_rewinddir()
public
dir_rewinddir() : mixed
disableBucketLogging()
Disable bucket logging
public
static disableBucketLogging(string $bucket) : bool
Parameters
- $bucket : string
-
Bucket name
Return values
boolfreeSigningKey()
Free signing key from memory, MUST be called if you are using setSigningKey()
public
static freeSigningKey() : void
getAccessControlPolicy()
Get object or bucket Access Control Policy
public
static getAccessControlPolicy(string $bucket[, string $uri = '' ]) : mixed|false
Parameters
- $bucket : string
-
Bucket name
- $uri : string = ''
-
Object URI
Return values
mixed|falsegetAuthenticatedURL()
Get a query string authenticated URL
public
static getAuthenticatedURL(string $bucket, string $uri, int $lifetime[, bool $hostBucket = false ][, bool $https = false ]) : string
Parameters
- $bucket : string
-
Bucket name
- $uri : string
-
Object URI
- $lifetime : int
-
Lifetime in seconds
- $hostBucket : bool = false
-
Use the bucket name as the hostname
- $https : bool = false
-
Use HTTPS ($hostBucket should be false for SSL verification)
Return values
stringgetBucket()
Get contents for a bucket
public
static getBucket(string $bucket[, string $prefix = null ][, string $marker = null ][, string $maxKeys = null ][, string $delimiter = null ][, bool $returnCommonPrefixes = false ]) : array<string|int, mixed>|false
If maxKeys is null this method will loop through truncated result sets
Parameters
- $bucket : string
-
Bucket name
- $prefix : string = null
-
Prefix
- $marker : string = null
-
Marker (last file listed)
- $maxKeys : string = null
-
Max keys (maximum number of keys to return)
- $delimiter : string = null
-
Delimiter
- $returnCommonPrefixes : bool = false
-
Set to true to return CommonPrefixes
Return values
array<string|int, mixed>|falsegetBucketLocation()
Get a bucket's location
public
static getBucketLocation(string $bucket) : string|false
Parameters
- $bucket : string
-
Bucket name
Return values
string|falsegetBucketLogging()
Get logging status for a bucket
public
static getBucketLogging(string $bucket) : array<string|int, mixed>|false
This will return false if logging is not enabled. Note: To enable logging, you also need to grant write access to the log group
Parameters
- $bucket : string
-
Bucket name
Return values
array<string|int, mixed>|falsegetDistribution()
Get CloudFront distribution info
public
static getDistribution(string $distributionId) : array<string|int, mixed>|false
Parameters
- $distributionId : string
-
Distribution ID from listDistributions()
Return values
array<string|int, mixed>|falsegetDistributionInvalidationList()
List your invalidation batches for invalidateDistribution() in a CloudFront distribution
public
static getDistributionInvalidationList(string $distributionId) : array<string|int, mixed>
http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/ListInvalidation.html returned array looks like this: Array ( [I31TWB0CN9V6XD] => InProgress [IT3TFE31M0IHZ] => Completed [I12HK7MPO1UQDA] => Completed [I1IA7R6JKTC3L2] => Completed )
Parameters
- $distributionId : string
-
Distribution ID from listDistributions()
Return values
array<string|int, mixed>getHttpUploadPostParams()
Get upload POST parameters for form uploads
public
static getHttpUploadPostParams(string $bucket[, string $uriPrefix = '' ][, constant $acl = self::ACL_PRIVATE ][, int $lifetime = 3600 ][, int $maxFileSize = 5242880 ][, string $successRedirect = "201" ][, array<string|int, mixed> $amzHeaders = array() ][, array<string|int, mixed> $headers = array() ][, bool $flashVars = false ]) : object
Parameters
- $bucket : string
-
Bucket name
- $uriPrefix : string = ''
-
Object URI prefix
- $acl : constant = self::ACL_PRIVATE
-
ACL constant
- $lifetime : int = 3600
-
Lifetime in seconds
- $maxFileSize : int = 5242880
-
Maximum filesize in bytes (default 5MB)
- $successRedirect : string = "201"
-
Redirect URL or 200 / 201 status code
- $amzHeaders : array<string|int, mixed> = array()
-
Array of x-amz-meta-* headers
- $headers : array<string|int, mixed> = array()
-
Array of request headers or content type as a string
- $flashVars : bool = false
-
Includes additional "Filename" variable posted by Flash
Return values
objectgetObject()
Get an object
public
static getObject(string $bucket, string $uri[, mixed $saveTo = false ]) : mixed
Parameters
- $bucket : string
-
Bucket name
- $uri : string
-
Object URI
- $saveTo : mixed = false
-
Filename or resource to write to
getObjectInfo()
Get object information
public
static getObjectInfo(string $bucket, string $uri[, bool $returnInfo = true ]) : mixed|false
Parameters
- $bucket : string
-
Bucket name
- $uri : string
-
Object URI
- $returnInfo : bool = true
-
Return response information
Return values
mixed|falsegetSignedCannedURL()
Get a CloudFront canned policy URL
public
static getSignedCannedURL(string $url, int $lifetime) : string
Parameters
- $url : string
-
URL to sign
- $lifetime : int
-
URL lifetime
Return values
stringgetSignedPolicyURL()
Get a CloudFront signed policy URL
public
static getSignedPolicyURL(array<string|int, mixed> $policy) : string
Parameters
- $policy : array<string|int, mixed>
-
Policy
Return values
stringhasAuth()
Check if AWS keys have been set
public
static hasAuth() : bool
Return values
boolinputFile()
Create input info array for putObject()
public
static inputFile(string $file[, mixed $md5sum = true ]) : array<string|int, mixed>|false
Parameters
- $file : string
-
Input file
- $md5sum : mixed = true
-
Use MD5 hash (supply a string if you want to use your own)
Return values
array<string|int, mixed>|falseinputResource()
Create input array info for putObject() with a resource
public
static inputResource(string &$resource[, int $bufferSize = false ][, string $md5sum = '' ]) : array<string|int, mixed>|false
Parameters
- $resource : string
-
Input resource to read from
- $bufferSize : int = false
-
Input byte size
- $md5sum : string = ''
-
MD5 hash to send (optional)
Return values
array<string|int, mixed>|falseinvalidateDistribution()
Invalidate objects in a CloudFront distribution
public
static invalidateDistribution(string $distributionId, array<string|int, mixed> $paths) : bool
Thanks to Martin Lindkvist for S3::invalidateDistribution()
Parameters
- $distributionId : string
-
Distribution ID from listDistributions()
- $paths : array<string|int, mixed>
-
Array of object paths to invalidate
Return values
boollistBuckets()
Get a list of buckets
public
static listBuckets([bool $detailed = false ]) : array<string|int, mixed>|false
Parameters
- $detailed : bool = false
-
Returns detailed bucket list when true
Return values
array<string|int, mixed>|falselistDistributions()
Get a list of CloudFront distributions
public
static listDistributions() : array<string|int, mixed>
Return values
array<string|int, mixed>listOriginAccessIdentities()
List CloudFront Origin Access Identities
public
static listOriginAccessIdentities() : array<string|int, mixed>
Return values
array<string|int, mixed>mkdir()
public
mkdir(mixed $path, mixed $mode, mixed $options) : mixed
Parameters
- $path : mixed
- $mode : mixed
- $options : mixed
putBucket()
Put a bucket
public
static putBucket(string $bucket[, constant $acl = self::ACL_PRIVATE ][, string $location = false ]) : bool
Parameters
- $bucket : string
-
Bucket name
- $acl : constant = self::ACL_PRIVATE
-
ACL flag
- $location : string = false
-
Set as "EU" to create buckets hosted in Europe
Return values
boolputObject()
Put an object
public
static putObject(mixed $input, string $bucket, string $uri[, constant $acl = self::ACL_PRIVATE ][, array<string|int, mixed> $metaHeaders = array() ][, array<string|int, mixed> $requestHeaders = array() ][, constant $storageClass = self::STORAGE_CLASS_STANDARD ][, constant $serverSideEncryption = self::SSE_NONE ]) : bool
Parameters
- $input : mixed
-
Input data
- $bucket : string
-
Bucket name
- $uri : string
-
Object URI
- $acl : constant = self::ACL_PRIVATE
-
ACL constant
- $metaHeaders : array<string|int, mixed> = array()
-
Array of x-amz-meta-* headers
- $requestHeaders : array<string|int, mixed> = array()
-
Array of request headers or content type as a string
- $storageClass : constant = self::STORAGE_CLASS_STANDARD
-
Storage class constant
- $serverSideEncryption : constant = self::SSE_NONE
-
Server-side encryption
Return values
boolputObjectFile()
Put an object from a file (legacy function)
public
static putObjectFile(string $file, string $bucket, string $uri[, constant $acl = self::ACL_PRIVATE ][, array<string|int, mixed> $metaHeaders = array() ][, string $contentType = null ]) : bool
Parameters
- $file : string
-
Input file path
- $bucket : string
-
Bucket name
- $uri : string
-
Object URI
- $acl : constant = self::ACL_PRIVATE
-
ACL constant
- $metaHeaders : array<string|int, mixed> = array()
-
Array of x-amz-meta-* headers
- $contentType : string = null
-
Content type
Return values
boolputObjectString()
Put an object from a string (legacy function)
public
static putObjectString(string $string, string $bucket, string $uri[, constant $acl = self::ACL_PRIVATE ][, array<string|int, mixed> $metaHeaders = array() ][, string $contentType = 'text/plain' ]) : bool
Parameters
- $string : string
-
Input data
- $bucket : string
-
Bucket name
- $uri : string
-
Object URI
- $acl : constant = self::ACL_PRIVATE
-
ACL constant
- $metaHeaders : array<string|int, mixed> = array()
-
Array of x-amz-meta-* headers
- $contentType : string = 'text/plain'
-
Content type
Return values
boolrmdir()
public
rmdir(mixed $path) : mixed
Parameters
- $path : mixed
setAccessControlPolicy()
Set object or bucket Access Control Policy
public
static setAccessControlPolicy(string $bucket[, string $uri = '' ][, array<string|int, mixed> $acp = array() ]) : bool
Parameters
- $bucket : string
-
Bucket name
- $uri : string = ''
-
Object URI
- $acp : array<string|int, mixed> = array()
-
Access Control Policy Data (same as the data returned from getAccessControlPolicy)
Return values
boolsetAuth()
Set AWS access key and secret key
public
static setAuth(string $accessKey, string $secretKey) : void
Parameters
- $accessKey : string
-
Access key
- $secretKey : string
-
Secret key
setBucketLogging()
Set logging for a bucket
public
static setBucketLogging(string $bucket, string $targetBucket[, string $targetPrefix = null ]) : bool
Parameters
- $bucket : string
-
Bucket name
- $targetBucket : string
-
Target bucket (where logs are stored)
- $targetPrefix : string = null
-
Log prefix (e,g; domain.com-)
Return values
boolsetBucketRedirect()
Set up a bucket redirection
public
static setBucketRedirect([string $bucket = null ][, string $location = null ]) : bool
Parameters
- $bucket : string = null
-
Bucket name
- $location : string = null
-
Target host name
Return values
boolsetEndpoint()
Set the service endpoint
public
setEndpoint(string $host) : void
Parameters
- $host : string
-
Hostname
setExceptions()
Set the error mode to exceptions
public
static setExceptions([bool $enabled = true ]) : void
Parameters
- $enabled : bool = true
-
Enable exceptions
setProxy()
Set proxy information
public
static setProxy(string $host[, string $user = null ][, string $pass = null ][, constant $type = CURLPROXY_SOCKS5 ]) : void
Parameters
- $host : string
-
Proxy hostname and port (localhost:1234)
- $user : string = null
-
Proxy username
- $pass : string = null
-
Proxy password
- $type : constant = CURLPROXY_SOCKS5
-
CURL proxy type
setSignatureVersion()
Set Signature Version
public
static setSignatureVersion([string $version = 'v2' ]) : void
Parameters
- $version : string = 'v2'
-
of signature ('v4' or 'v2')
setSigningKey()
Set signing key
public
static setSigningKey(string $keyPairId, string $signingKey[, bool $isFile = true ]) : bool
Parameters
- $keyPairId : string
-
AWS Key Pair ID
- $signingKey : string
-
Private Key
- $isFile : bool = true
-
Load private key from file, set to false to load string
Return values
boolsetSSL()
Set SSL on or off
public
static setSSL(bool $enabled[, bool $validate = true ]) : void
Parameters
- $enabled : bool
-
SSL enabled
- $validate : bool = true
-
SSL certificate validation
setSSLAuth()
Set SSL client certificates (experimental)
public
static setSSLAuth([string $sslCert = null ][, string $sslKey = null ][, string $sslCACert = null ]) : void
Parameters
- $sslCert : string = null
-
SSL client certificate
- $sslKey : string = null
-
SSL client key
- $sslCACert : string = null
-
SSL CA cert (only required if you are having problems with your system CA cert)
setTimeCorrectionOffset()
Set AWS time correction offset (use carefully)
public
static setTimeCorrectionOffset([string $offset = 0 ]) : void
This can be used when an inaccurate system time is generating invalid request signatures. It should only be used as a last resort when the system time cannot be changed.
Parameters
- $offset : string = 0
-
Time offset (set to zero to use AWS server time)
stream_close()
public
stream_close() : mixed
stream_eof()
public
stream_eof() : mixed
stream_flush()
public
stream_flush() : mixed
stream_open()
public
stream_open(mixed $path, mixed $mode, mixed $options, mixed &$opened_path) : mixed
Parameters
- $path : mixed
- $mode : mixed
- $options : mixed
- $opened_path : mixed
stream_read()
public
stream_read(mixed $count) : mixed
Parameters
- $count : mixed
stream_seek()
public
stream_seek(mixed $offset, mixed $whence) : mixed
Parameters
- $offset : mixed
- $whence : mixed
stream_stat()
public
stream_stat() : mixed
stream_tell()
public
stream_tell() : mixed
stream_write()
public
stream_write(mixed $data) : mixed
Parameters
- $data : mixed
unlink()
public
unlink(mixed $path) : mixed
Parameters
- $path : mixed
updateDistribution()
Update a CloudFront distribution
public
static updateDistribution(array<string|int, mixed> $dist) : array<string|int, mixed>|false
Parameters
- $dist : array<string|int, mixed>
-
Distribution array info identical to output of getDistribution()
Return values
array<string|int, mixed>|falseurl_stat()
public
url_stat(mixed $path, mixed $flags) : mixed
Parameters
- $path : mixed
- $flags : mixed
__getURL()
private
__getURL(mixed $path) : mixed
Parameters
- $path : mixed
__translateMode()
private
__translateMode(mixed $mode) : mixed
Parameters
- $mode : mixed