Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
S3 Class Reference

Amazon S3 PHP class. More...

Public Member Functions

 __construct ($accessKey=null, $secretKey=null, $useSSL=false, $endpoint='s3.amazonaws.com')
 Constructor - if you're not using the class statically.
 
 setEndpoint ($host)
 Set the service endpoint.
 

Static Public Member Functions

static __getSignature ($string)
 Generate the auth string: "AWS AccessKey:Signature".
 
static __getTime ()
 Get the current time.
 
static copyObject ($srcBucket, $srcUri, $bucket, $uri, $acl=self::ACL_PRIVATE, $metaHeaders=array(), $requestHeaders=array(), $storageClass=self::STORAGE_CLASS_STANDARD)
 Copy an object.
 
static createDistribution ($bucket, $enabled=true, $cnames=array(), $comment=null, $defaultRootObject=null, $originAccessIdentity=null, $trustedSigners=array())
 Create a CloudFront distribution.
 
static deleteBucket ($bucket)
 Delete an empty bucket.
 
static deleteDistribution ($dist)
 Delete a CloudFront distribution.
 
static deleteObject ($bucket, $uri)
 Delete an object.
 
static disableBucketLogging ($bucket)
 Disable bucket logging.
 
static freeSigningKey ()
 Free signing key from memory, MUST be called if you are using setSigningKey()
 
static getAccessControlPolicy ($bucket, $uri='')
 Get object or bucket Access Control Policy.
 
static getAuthenticatedURL ($bucket, $uri, $lifetime, $hostBucket=false, $https=false)
 Get a query string authenticated URL.
 
static getBucket ($bucket, $prefix=null, $marker=null, $maxKeys=null, $delimiter=null, $returnCommonPrefixes=false)
 Get contents for a bucket.
 
static getBucketLocation ($bucket)
 Get a bucket's location.
 
static getBucketLogging ($bucket)
 Get logging status for a bucket.
 
static getDistribution ($distributionId)
 Get CloudFront distribution info.
 
static getDistributionInvalidationList ($distributionId)
 List your invalidation batches for invalidateDistribution() in a CloudFront distribution.
 
static getHttpUploadPostParams ($bucket, $uriPrefix='', $acl=self::ACL_PRIVATE, $lifetime=3600, $maxFileSize=5242880, $successRedirect="201", $amzHeaders=array(), $headers=array(), $flashVars=false)
 Get upload POST parameters for form uploads.
 
static getObject ($bucket, $uri, $saveTo=false)
 Get an object.
 
static getObjectInfo ($bucket, $uri, $returnInfo=true)
 Get object information.
 
static getSignedCannedURL ($url, $lifetime)
 Get a CloudFront canned policy URL.
 
static getSignedPolicyURL ($policy)
 Get a CloudFront signed policy URL.
 
static hasAuth ()
 Check if AWS keys have been set.
 
static inputFile ($file, $md5sum=true)
 Create input info array for putObject()
 
static inputResource (&$resource, $bufferSize=false, $md5sum='')
 Create input array info for putObject() with a resource.
 
static invalidateDistribution ($distributionId, $paths)
 Invalidate objects in a CloudFront distribution.
 
static listBuckets ($detailed=false)
 Get a list of buckets.
 
static listDistributions ()
 Get a list of CloudFront distributions.
 
static listOriginAccessIdentities ()
 List CloudFront Origin Access Identities.
 
static putBucket ($bucket, $acl=self::ACL_PRIVATE, $location=false)
 Put a bucket.
 
static putObject ($input, $bucket, $uri, $acl=self::ACL_PRIVATE, $metaHeaders=array(), $requestHeaders=array(), $storageClass=self::STORAGE_CLASS_STANDARD, $serverSideEncryption=self::SSE_NONE)
 Put an object.
 
static putObjectFile ($file, $bucket, $uri, $acl=self::ACL_PRIVATE, $metaHeaders=array(), $contentType=null)
 Put an object from a file (legacy function)
 
static putObjectString ($string, $bucket, $uri, $acl=self::ACL_PRIVATE, $metaHeaders=array(), $contentType='text/plain')
 Put an object from a string (legacy function)
 
static setAccessControlPolicy ($bucket, $uri='', $acp=array())
 Set object or bucket Access Control Policy.
 
static setAuth ($accessKey, $secretKey)
 Set AWS access key and secret key.
 
static setBucketLogging ($bucket, $targetBucket, $targetPrefix=null)
 Set logging for a bucket.
 
static setBucketRedirect ($bucket=NULL, $location=NULL)
 Set up a bucket redirection.
 
static setExceptions ($enabled=true)
 Set the error mode to exceptions.
 
static setProxy ($host, $user=null, $pass=null, $type=CURLPROXY_SOCKS5)
 Set proxy information.
 
static setSigningKey ($keyPairId, $signingKey, $isFile=true)
 Set signing key.
 
static setSSL ($enabled, $validate=true)
 Set SSL on or off.
 
static setSSLAuth ($sslCert=null, $sslKey=null, $sslCACert=null)
 Set SSL client certificates (experimental)
 
static setTimeCorrectionOffset ($offset=0)
 Set AWS time correction offset (use carefully)
 
static updateDistribution ($dist)
 Update a CloudFront distribution.
 

Public Attributes

const ACL_AUTHENTICATED_READ = 'authenticated-read'
 
const ACL_PRIVATE = 'private'
 
const ACL_PUBLIC_READ = 'public-read'
 
const ACL_PUBLIC_READ_WRITE = 'public-read-write'
 
const SSE_AES256 = 'AES256'
 
const SSE_NONE = ''
 
const STORAGE_CLASS_RRS = 'REDUCED_REDUNDANCY'
 
const STORAGE_CLASS_STANDARD = 'STANDARD'
 

Static Public Attributes

static string $defDelimiter = null
 Default delimiter to be used, for example while getBucket().
 
static string $endpoint = 's3.amazonaws.com'
 AWS URI.
 
static null array $proxy = null
 Proxy information.
 
static string $sslCACert = null
 SSL CA cert (only required if you are having problems with your system CA cert)
 
static string $sslCert = null
 SSL client certfificate.
 
static bool $sslKey = null
 SSL client key.
 
static bool $useExceptions = false
 Use PHP exceptions?
 
static bool $useSSL = false
 Connect using SSL?
 
static bool $useSSLValidation = true
 Use SSL validation?
 
static const $useSSLVersion = CURL_SSLVERSION_TLSv1
 Use SSL version.
 

Detailed Description

Amazon S3 PHP class.

@externalurl http://undesigned.org.za/2007/10/22/amazon-s3-php-class

Version
0.5.1

Constructor & Destructor Documentation

◆ __construct()

S3::__construct ( $accessKey = null,
$secretKey = null,
$useSSL = false,
$endpoint = 's3.amazonaws.com' )

Constructor - if you're not using the class statically.

Parameters
string$accessKeyAccess key
string$secretKeySecret key
boolean$useSSLEnable SSL
string$endpointAmazon URI
Return values
void

Member Function Documentation

◆ copyObject()

static S3::copyObject ( $srcBucket,
$srcUri,
$bucket,
$uri,
$acl = self::ACL_PRIVATE,
$metaHeaders = array(),
$requestHeaders = array(),
$storageClass = self::STORAGE_CLASS_STANDARD )
static

Copy an object.

Parameters
string$srcBucketSource bucket name
string$srcUriSource object URI
string$bucketDestination bucket name
string$uriDestination object URI
constant$aclACL constant
array$metaHeadersOptional array of x-amz-meta-* headers
array$requestHeadersOptional array of request headers (content type, disposition, etc.)
constant$storageClassStorage class constant
Return values
mixed| false

◆ createDistribution()

static S3::createDistribution ( $bucket,
$enabled = true,
$cnames = array(),
$comment = null,
$defaultRootObject = null,
$originAccessIdentity = null,
$trustedSigners = array() )
static

Create a CloudFront distribution.

Parameters
string$bucketBucket name
boolean$enabledEnabled (true/false)
array$cnamesArray containing CNAME aliases
string$commentUse the bucket name as the hostname
string$defaultRootObjectDefault root object
string$originAccessIdentityOrigin access identity
array$trustedSignersArray of trusted signers
Return values
array| false

◆ deleteBucket()

static S3::deleteBucket ( $bucket)
static

Delete an empty bucket.

Parameters
string$bucketBucket name
Return values
boolean

◆ deleteDistribution()

static S3::deleteDistribution ( $dist)
static

Delete a CloudFront distribution.

Parameters
array$distDistribution array info identical to output of getDistribution()
Return values
boolean

◆ deleteObject()

static S3::deleteObject ( $bucket,
$uri )
static

Delete an object.

Parameters
string$bucketBucket name
string$uriObject URI
Return values
boolean

◆ disableBucketLogging()

static S3::disableBucketLogging ( $bucket)
static

Disable bucket logging.

Parameters
string$bucketBucket name
Return values
boolean

◆ freeSigningKey()

static S3::freeSigningKey ( )
static

Free signing key from memory, MUST be called if you are using setSigningKey()

Return values
void

◆ getAccessControlPolicy()

static S3::getAccessControlPolicy ( $bucket,
$uri = '' )
static

Get object or bucket Access Control Policy.

Parameters
string$bucketBucket name
string$uriObject URI
Return values
mixed| false

◆ getAuthenticatedURL()

static S3::getAuthenticatedURL ( $bucket,
$uri,
$lifetime,
$hostBucket = false,
$https = false )
static

Get a query string authenticated URL.

Parameters
string$bucketBucket name
string$uriObject URI
integer$lifetimeLifetime in seconds
boolean$hostBucketUse the bucket name as the hostname
boolean$httpsUse HTTPS ($hostBucket should be false for SSL verification)
Return values
string

◆ getBucket()

static S3::getBucket ( $bucket,
$prefix = null,
$marker = null,
$maxKeys = null,
$delimiter = null,
$returnCommonPrefixes = false )
static

Get contents for a bucket.

If maxKeys is null this method will loop through truncated result sets

Parameters
string$bucketBucket name
string$prefixPrefix
string$markerMarker (last file listed)
string$maxKeysMax keys (maximum number of keys to return)
string$delimiterDelimiter
boolean$returnCommonPrefixesSet to true to return CommonPrefixes
Return values
array| false

◆ getBucketLocation()

static S3::getBucketLocation ( $bucket)
static

Get a bucket's location.

Parameters
string$bucketBucket name
Return values
string| false

◆ getBucketLogging()

static S3::getBucketLogging ( $bucket)
static

Get logging status for a bucket.

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
string$bucketBucket name
Return values
array| false

◆ getDistribution()

static S3::getDistribution ( $distributionId)
static

Get CloudFront distribution info.

Parameters
string$distributionIdDistribution ID from listDistributions()
Return values
array| false

◆ getDistributionInvalidationList()

static S3::getDistributionInvalidationList ( $distributionId)
static

List your invalidation batches for invalidateDistribution() in a CloudFront distribution.

http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/ListInvalidation.html returned array looks like this: Array ( [I31TWB0CN9V6XD] => InProgress [IT3TFE31M0IHZ] => Completed [I12HK7MPO1UQDA] => Completed [I1IA7R6JKTC3L2] => Completed )

Parameters
string$distributionIdDistribution ID from listDistributions()
Return values
array

◆ getHttpUploadPostParams()

static S3::getHttpUploadPostParams ( $bucket,
$uriPrefix = '',
$acl = self::ACL_PRIVATE,
$lifetime = 3600,
$maxFileSize = 5242880,
$successRedirect = "201",
$amzHeaders = array(),
$headers = array(),
$flashVars = false )
static

Get upload POST parameters for form uploads.

Parameters
string$bucketBucket name
string$uriPrefixObject URI prefix
constant$aclACL constant
integer$lifetimeLifetime in seconds
integer$maxFileSizeMaximum filesize in bytes (default 5MB)
string$successRedirectRedirect URL or 200 / 201 status code
array$amzHeadersArray of x-amz-meta-* headers
array$headersArray of request headers or content type as a string
boolean$flashVarsIncludes additional "Filename" variable posted by Flash
Return values
object

◆ getObject()

static S3::getObject ( $bucket,
$uri,
$saveTo = false )
static

Get an object.

Parameters
string$bucketBucket name
string$uriObject URI
mixed$saveToFilename or resource to write to
Return values
mixed

◆ getObjectInfo()

static S3::getObjectInfo ( $bucket,
$uri,
$returnInfo = true )
static

Get object information.

Parameters
string$bucketBucket name
string$uriObject URI
boolean$returnInfoReturn response information
Return values
mixed| false

◆ getSignedCannedURL()

static S3::getSignedCannedURL ( $url,
$lifetime )
static

Get a CloudFront canned policy URL.

Parameters
string$urlURL to sign
integer$lifetimeURL lifetime
Return values
string

◆ getSignedPolicyURL()

static S3::getSignedPolicyURL ( $policy)
static

Get a CloudFront signed policy URL.

Parameters
array$policyPolicy
Return values
string

◆ hasAuth()

static S3::hasAuth ( )
static

Check if AWS keys have been set.

Return values
boolean

◆ inputFile()

static S3::inputFile ( $file,
$md5sum = true )
static

Create input info array for putObject()

Parameters
string$fileInput file
mixed$md5sumUse MD5 hash (supply a string if you want to use your own)
Return values
array| false

◆ inputResource()

static S3::inputResource ( & $resource,
$bufferSize = false,
$md5sum = '' )
static

Create input array info for putObject() with a resource.

Parameters
string$resourceInput resource to read from
integer$bufferSizeInput byte size
string$md5sumMD5 hash to send (optional)
Return values
array| false

◆ invalidateDistribution()

static S3::invalidateDistribution ( $distributionId,
$paths )
static

Invalidate objects in a CloudFront distribution.

Thanks to Martin Lindkvist for S3\invalidateDistribution()

Parameters
string$distributionIdDistribution ID from listDistributions()
array$pathsArray of object paths to invalidate
Return values
boolean

◆ listBuckets()

static S3::listBuckets ( $detailed = false)
static

Get a list of buckets.

Parameters
boolean$detailedReturns detailed bucket list when true
Return values
array| false

◆ listDistributions()

static S3::listDistributions ( )
static

Get a list of CloudFront distributions.

Return values
array

◆ listOriginAccessIdentities()

static S3::listOriginAccessIdentities ( )
static

List CloudFront Origin Access Identities.

Return values
array

◆ putBucket()

static S3::putBucket ( $bucket,
$acl = self::ACL_PRIVATE,
$location = false )
static

Put a bucket.

Parameters
string$bucketBucket name
constant$aclACL flag
string$locationSet as "EU" to create buckets hosted in Europe
Return values
boolean

◆ putObject()

static S3::putObject ( $input,
$bucket,
$uri,
$acl = self::ACL_PRIVATE,
$metaHeaders = array(),
$requestHeaders = array(),
$storageClass = self::STORAGE_CLASS_STANDARD,
$serverSideEncryption = self::SSE_NONE )
static

Put an object.

Parameters
mixed$inputInput data
string$bucketBucket name
string$uriObject URI
constant$aclACL constant
array$metaHeadersArray of x-amz-meta-* headers
array$requestHeadersArray of request headers or content type as a string
constant$storageClassStorage class constant
constant$serverSideEncryptionServer-side encryption
Return values
boolean

◆ putObjectFile()

static S3::putObjectFile ( $file,
$bucket,
$uri,
$acl = self::ACL_PRIVATE,
$metaHeaders = array(),
$contentType = null )
static

Put an object from a file (legacy function)

Parameters
string$fileInput file path
string$bucketBucket name
string$uriObject URI
constant$aclACL constant
array$metaHeadersArray of x-amz-meta-* headers
string$contentTypeContent type
Return values
boolean

◆ putObjectString()

static S3::putObjectString ( $string,
$bucket,
$uri,
$acl = self::ACL_PRIVATE,
$metaHeaders = array(),
$contentType = 'text/plain' )
static

Put an object from a string (legacy function)

Parameters
string$stringInput data
string$bucketBucket name
string$uriObject URI
constant$aclACL constant
array$metaHeadersArray of x-amz-meta-* headers
string$contentTypeContent type
Return values
boolean

◆ setAccessControlPolicy()

static S3::setAccessControlPolicy ( $bucket,
$uri = '',
$acp = array() )
static

Set object or bucket Access Control Policy.

Parameters
string$bucketBucket name
string$uriObject URI
array$acpAccess Control Policy Data (same as the data returned from getAccessControlPolicy)
Return values
boolean

◆ setAuth()

static S3::setAuth ( $accessKey,
$secretKey )
static

Set AWS access key and secret key.

Parameters
string$accessKeyAccess key
string$secretKeySecret key
Return values
void

◆ setBucketLogging()

static S3::setBucketLogging ( $bucket,
$targetBucket,
$targetPrefix = null )
static

Set logging for a bucket.

Parameters
string$bucketBucket name
string$targetBucketTarget bucket (where logs are stored)
string$targetPrefixLog prefix (e,g; domain.com-)
Return values
boolean

◆ setBucketRedirect()

static S3::setBucketRedirect ( $bucket = NULL,
$location = NULL )
static

Set up a bucket redirection.

Parameters
string$bucketBucket name
string$locationTarget host name
Return values
boolean

◆ setEndpoint()

S3::setEndpoint ( $host)

Set the service endpoint.

Parameters
string$hostHostname
Return values
void

◆ setExceptions()

static S3::setExceptions ( $enabled = true)
static

Set the error mode to exceptions.

Parameters
boolean$enabledEnable exceptions
Return values
void

◆ setProxy()

static S3::setProxy ( $host,
$user = null,
$pass = null,
$type = CURLPROXY_SOCKS5 )
static

Set proxy information.

Parameters
string$hostProxy hostname and port (localhost:1234)
string$userProxy username
string$passProxy password
constant$typeCURL proxy type
Return values
void

◆ setSigningKey()

static S3::setSigningKey ( $keyPairId,
$signingKey,
$isFile = true )
static

Set signing key.

Parameters
string$keyPairIdAWS Key Pair ID
string$signingKeyPrivate Key
boolean$isFileLoad private key from file, set to false to load string
Return values
boolean

◆ setSSL()

static S3::setSSL ( $enabled,
$validate = true )
static

Set SSL on or off.

Parameters
boolean$enabledSSL enabled
boolean$validateSSL certificate validation
Return values
void

◆ setSSLAuth()

static S3::setSSLAuth ( $sslCert = null,
$sslKey = null,
$sslCACert = null )
static

Set SSL client certificates (experimental)

Parameters
string$sslCertSSL client certificate
string$sslKeySSL client key
string$sslCACertSSL CA cert (only required if you are having problems with your system CA cert)
Return values
void

◆ setTimeCorrectionOffset()

static S3::setTimeCorrectionOffset ( $offset = 0)
static

Set AWS time correction offset (use carefully)

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
string$offsetTime offset (set to zero to use AWS server time)
Return values
void

◆ updateDistribution()

static S3::updateDistribution ( $dist)
static

Update a CloudFront distribution.

Parameters
array$distDistribution array info identical to output of getDistribution()
Return values
array| false

Member Data Documentation

◆ $endpoint

string S3::$endpoint = 's3.amazonaws.com'
static

AWS URI.

@acess public

◆ $sslCert

string S3::$sslCert = null
static

SSL client certfificate.

@acess public


The documentation for this class was generated from the following file: