Untitled diff

Created Diff never expires
0 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
885 lines
0 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
885 lines
<?php
<?php
/**
/**
* $Id$
* $Id$
*
*
* Copyright (c) 2013, Donovan Schönknecht. All rights reserved.
* Copyright (c) 2013, Donovan Schönknecht. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* modification, are permitted provided that the following conditions are met:
*
*
* - Redistributions of source code must retain the above copyright notice,
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* documentation and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* POSSIBILITY OF SUCH DAMAGE.
*
*
* Amazon S3 is a trademark of Amazon.com, Inc. or its affiliates.
* Amazon S3 is a trademark of Amazon.com, Inc. or its affiliates.
*/
*/


/**
/**
* Amazon S3 PHP class
* Amazon S3 PHP class
*
*
* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
* @version 0.5.1
* @version 0.5.1
*/
*/
class S3
class S3
{
{
// ACL flags
// ACL flags
const ACL_PRIVATE = 'private';
const ACL_PRIVATE = 'private';
const ACL_PUBLIC_READ = 'public-read';
const ACL_PUBLIC_READ = 'public-read';
const ACL_PUBLIC_READ_WRITE = 'public-read-write';
const ACL_PUBLIC_READ_WRITE = 'public-read-write';
const ACL_AUTHENTICATED_READ = 'authenticated-read';
const ACL_AUTHENTICATED_READ = 'authenticated-read';


const STORAGE_CLASS_STANDARD = 'STANDARD';
const STORAGE_CLASS_STANDARD = 'STANDARD';
const STORAGE_CLASS_RRS = 'REDUCED_REDUNDANCY';
const STORAGE_CLASS_RRS = 'REDUCED_REDUNDANCY';
const STORAGE_CLASS_STANDARD_IA = 'STANDARD_IA';
const STORAGE_CLASS_STANDARD_IA = 'STANDARD_IA';


const SSE_NONE = '';
const SSE_NONE = '';
const SSE_AES256 = 'AES256';
const SSE_AES256 = 'AES256';


/**
/**
* The AWS Access key
* The AWS Access key
*
*
* @var string
* @var string
* @access private
* @access private
* @static
* @static
*/
*/
private static $__accessKey = null;
private static $__accessKey = null;


/**
/**
* AWS Secret Key
* AWS Secret Key
*
*
* @var string
* @var string
* @access private
* @access private
* @static
* @static
*/
*/
private static $__secretKey = null;
private static $__secretKey = null;


/**
/**
* SSL Client key
* SSL Client key
*
*
* @var string
* @var string
* @access private
* @access private
* @static
* @static
*/
*/
private static $__sslKey = null;
private static $__sslKey = null;


/**
/**
* Default delimiter to be used, for example while getBucket().
* Default delimiter to be used, for example while getBucket().
* @var string
* @var string
* @access public
* @access public
* @static
* @static
*/
*/
public static $defDelimiter = null;
public static $defDelimiter = null;


/**
/**
* AWS URI
* AWS URI
*
*
* @var string
* @var string
* @acess public
* @acess public
* @static
* @static
*/
*/
public static $endpoint = 's3.amazonaws.com';
public static $endpoint = 's3.amazonaws.com';


/**
/**
* AWS Region
* AWS Region
*
*
* @var string
* @var string
* @acess public
* @acess public
* @static
* @static
*/
*/
public static $region = '';
public static $region = '';


/**
/**
* Proxy information
* Proxy information
*
*
* @var null|array
* @var null|array
* @access public
* @access public
* @static
* @static
*/
*/
public static $proxy = null;
public static $proxy = null;


/**
/**
* Connect using SSL?
* Connect using SSL?
*
*
* @var bool
* @var bool
* @access public
* @access public
* @static
* @static
*/
*/
public static $useSSL = false;
public static $useSSL = false;


/**
/**
* Use SSL validation?
* Use SSL validation?
*
*
* @var bool
* @var bool
* @access public
* @access public
* @static
* @static
*/
*/
public static $useSSLValidation = true;
public static $useSSLValidation = true;


/**
/**
* Use SSL version
* Use SSL version
*
*
* @var const
* @var const
* @access public
* @access public
* @static
* @static
*/
*/
public static $useSSLVersion = CURL_SSLVERSION_TLSv1;
public static $useSSLVersion = CURL_SSLVERSION_TLSv1;


/**
/**
* Use PHP exceptions?
* Use PHP exceptions?
*
*
* @var bool
* @var bool
* @access public
* @access public
* @static
* @static
*/
*/
public static $useExceptions = false;
public static $useExceptions = false;


/**
/**
* Time offset applied to time()
* Time offset applied to time()
* @access private
* @access private
* @static
* @static
*/
*/
private static $__timeOffset = 0;
private static $__timeOffset = 0;


/**
/**
* SSL client key
* SSL client key
*
*
* @var bool
* @var bool
* @access public
* @access public
* @static
* @static
*/
*/
public static $sslKey = null;
public static $sslKey = null;
/**
/**
* SSL client certfificate
* SSL client certfificate
*
*
* @var string
* @var string
* @acess public
* @acess public
* @static
* @static
*/
*/
public static $sslCert = null;
public static $sslCert = null;
/**
/**
* SSL CA cert (only required if you are having problems with your system CA cert)
* SSL CA cert (only required if you are having problems with your system CA cert)
*
*
* @var string
* @var string
* @access public
* @access public
* @static
* @static
*/
*/
public static $sslCACert = null;
public static $sslCACert = null;
/**
/**
* AWS Key Pair ID
* AWS Key Pair ID
*
*
* @var string
* @var string
* @access private
* @access private
* @static
* @static
*/
*/
private static $__signingKeyPairId = null;
private static $__signingKeyPairId = null;
/**
/**
* Key resource, freeSigningKey() must be called to clear it from memory
* Key resource, freeSigningKey() must be called to clear it from memory
*
*
* @var bool
* @var bool
* @access private
* @access private
* @static
* @static
*/
*/
private static $__signingKeyResource = false;
private static $__signingKeyResource = false;


/**
/**
* CURL progress function callback
* CURL progress function callback
*
*
* @var function
* @var function
* @access public
* @access public
* @static
* @static
*/
*/
public static $progressFunction = null;
public static $progressFunction = null;


/**
/**
* Constructor - if you're not using the class statically
* Constructor - if you're not using the class statically
*
*
* @param string $accessKey Access key
* @param string $accessKey Access key
* @param string $secretKey Secret key
* @param string $secretKey Secret key
* @param boolean $useSSL Enable SSL
* @param boolean $useSSL Enable SSL
* @param string $endpoint Amazon URI
* @param string $endpoint Amazon URI
* @return void
* @return void
*/
*/
public function __construct($accessKey = null, $secretKey = null, $useSSL = false, $endpoint = 's3.amazonaws.com', $region = '')
public function __construct($accessKey = null, $secretKey = null, $useSSL = false, $endpoint = 's3.amazonaws.com', $region = '')
{
{
if ($accessKey !== null && $secretKey !== null)
if ($accessKey !== null && $secretKey !== null)
self::setAuth($accessKey, $secretKey);
self::setAuth($accessKey, $secretKey);
self::$useSSL = $useSSL;
self::$useSSL = $useSSL;
self::$endpoint = $endpoint;
self::$endpoint = $endpoint;
self::$region = $region;
self::$region = $region;
}
}




/**
/**
* Set the service endpoint
* Set the service endpoint
*
*
* @param string $host Hostname
* @param string $host Hostname
* @return void
* @return void
*/
*/
public function setEndpoint($host)
public function setEndpoint($host)
{
{
self::$endpoint = $host;
self::$endpoint = $host;
}
}




/**
/**
* Set the service region
* Set the service region
*
*
* @param string $region
* @param string $region
* @return void
* @return void
*/
*/
public function setRegion($region)
public function setRegion($region)
{
{
self::$region = $region;
self::$region = $region;
}
}




/**
/**
* Get the service region
* Get the service region
*
*
* @return string $region
* @return string $region
* @static
* @static
*/
*/
public static function getRegion()
public static function getRegion()
{
{
$region = self::$region;
$region = self::$region;


// parse region from endpoint if not specific
// parse region from endpoint if not specific
if (empty($region))
if (empty($region))
{
{
if (preg_match("/s3[.-](?:website-|dualstack\.)?(.+)\.amazonaws\.com/i", self::$endpoint, $match) !== 0
if (preg_match("/s3[.-](?:website-|dualstack\.)?(.+)\.amazonaws\.com/i", self::$endpoint, $match) !== 0
&& strtolower($match[1]) !== "external-1")
&& strtolower($match[1]) !== "external-1")
{
{
$region = $match[1];
$region = $match[1];
}
}
}
}


return empty($region) ? 'us-east-1' : $region;
return empty($region) ? 'us-east-1' : $region;
}
}




/**
/**
* Set AWS access key and secret key
* Set AWS access key and secret key
*
*
* @param string $accessKey Access key
* @param string $accessKey Access key
* @param string $secretKey Secret key
* @param string $secretKey Secret key
* @return void
* @return void
*/
*/
public static function setAuth($accessKey, $secretKey)
public static function setAuth($accessKey, $secretKey)
{
{
self::$__accessKey = $accessKey;
self::$__accessKey = $accessKey;
self::$__secretKey = $secretKey;
self::$__secretKey = $secretKey;
}
}




/**
/**
* Check if AWS keys have been set
* Check if AWS keys have been set
*
*
* @return boolean
* @return boolean
*/
*/
public static function hasAuth() {
public static function hasAuth() {
return (self::$__accessKey !== null && self::$__secretKey !== null);
return (self::$__accessKey !== null && self::$__secretKey !== null);
}
}




/**
/**
* Set SSL on or off
* Set SSL on or off
*
*
* @param boolean $enabled SSL enabled
* @param boolean $enabled SSL enabled
* @param boolean $validate SSL certificate validation
* @param boolean $validate SSL certificate validation
* @return void
* @return void
*/
*/
public static function setSSL($enabled, $validate = true)
public static function setSSL($enabled, $validate = true)
{
{
self::$useSSL = $enabled;
self::$useSSL = $enabled;
self::$useSSLValidation = $validate;
self::$useSSLValidation = $validate;
}
}




/**
/**
* Set SSL client certificates (experimental)
* Set SSL client certificates (experimental)
*
*
* @param string $sslCert SSL client certificate
* @param string $sslCert SSL client certificate
* @param string $sslKey SSL client key
* @param string $sslKey SSL client key
* @param string $sslCACert SSL CA cert (only required if you are having problems with your system CA cert)
* @param string $sslCACert SSL CA cert (only required if you are having problems with your system CA cert)
* @return void
* @return void
*/
*/
public static function setSSLAuth($sslCert = null, $sslKey = null, $sslCACert = null)
public static function setSSLAuth($sslCert = null, $sslKey = null, $sslCACert = null)
{
{
self::$sslCert = $sslCert;
self::$sslCert = $sslCert;
self::$sslKey = $sslKey;
self::$sslKey = $sslKey;
self::$sslCACert = $sslCACert;
self::$sslCACert = $sslCACert;
}
}




/**
/**
* Set proxy information
* Set proxy information
*
*
* @param string $host Proxy hostname and port (localhost:1234)
* @param string $host Proxy hostname and port (localhost:1234)
* @param string $user Proxy username
* @param string $user Proxy username
* @param string $pass Proxy password
* @param string $pass Proxy password
* @param constant $type CURL proxy type
* @param constant $type CURL proxy type
* @return void
* @return void
*/
*/
public static function setProxy($host, $user = null, $pass = null, $type = CURLPROXY_SOCKS5)
public static function setProxy($host, $user = null, $pass = null, $type = CURLPROXY_SOCKS5)
{
{
self::$proxy = array('host' => $host, 'type' => $type, 'user' => $user, 'pass' => $pass);
self::$proxy = array('host' => $host, 'type' => $type, 'user' => $user, 'pass' => $pass);
}
}




/**
/**
* Set the error mode to exceptions
* Set the error mode to exceptions
*
*
* @param boolean $enabled Enable exceptions
* @param boolean $enabled Enable exceptions
* @return void
* @return void
*/
*/
public static function setExceptions($enabled = true)
public static function setExceptions($enabled = true)
{
{
self::$useExceptions = $enabled;
self::$useExceptions = $enabled;
}
}




/**
/**
* Set AWS time correction offset (use carefully)
* Set AWS time correction offset (use carefully)
*
*
* This can be used when an inaccurate system time is generating
* This can be used when an inaccurate system time is generating
* invalid request signatures. It should only be used as a last
* invalid request signatures. It should only be used as a last
* resort when the system time cannot be changed.
* resort when the system time cannot be changed.
*
*
* @param string $offset Time offset (set to zero to use AWS server time)
* @param string $offset Time offset (set to zero to use AWS server time)
* @return void
* @return void
*/
*/
public static function setTimeCorrectionOffset($offset = 0)
public static function setTimeCorrectionOffset($offset = 0)
{
{
if ($offset == 0)
if ($offset == 0)
{
{
$rest = new S3Request('HEAD');
$rest = new S3Request('HEAD');
$rest = $rest->getResponse();
$rest = $rest->getResponse();
$awstime = $rest->headers['date'];
$awstime = $rest->headers['date'];
$systime = time();
$systime = time();
$offset = $systime > $awstime ? -($systime - $awstime) : ($awstime - $systime);
$offset = $systime > $awstime ? -($systime - $awstime) : ($awstime - $systime);
}
}
self::$__timeOffset = $offset;
self::$__timeOffset = $offset;
}
}




/**
/**
* Set signing key
* Set signing key
*
*
* @param string $keyPairId AWS Key Pair ID
* @param string $keyPairId AWS Key Pair ID
* @param string $signingKey Private Key
* @param string $signingKey Private Key
* @param boolean $isFile Load private key from file, set to false to load string
* @param boolean $isFile Load private key from file, set to false to load string
* @return boolean
* @return boolean
*/
*/
public static function setSigningKey($keyPairId, $signingKey, $isFile = true)
public static function setSigningKey($keyPairId, $signingKey, $isFile = true)
{
{
self::$__signingKeyPairId = $keyPairId;
self::$__signingKeyPairId = $keyPairId;
if ((self::$__signingKeyResource = openssl_pkey_get_private($isFile ?
if ((self::$__signingKeyResource = openssl_pkey_get_private($isFile ?
file_get_contents($signingKey) : $signingKey)) !== false) return true;
file_get_contents($signingKey) : $signingKey)) !== false) return true;
self::__triggerError('S3::setSigningKey(): Unable to open load private key: '.$signingKey, __FILE__, __LINE__);
self::__triggerError('S3::setSigningKey(): Unable to open load private key: '.$signingKey, __FILE__, __LINE__);
return false;
return false;
}
}






/**
/**
* Free signing key from memory, MUST be called if you are using setSigningKey()
* Free signing key from memory, MUST be called if you are using setSigningKey()
*
*
* @return void
* @return void
*/
*/
public static function freeSigningKey()
public static function freeSigningKey()
{
{
if (self::$__signingKeyResource !== false)
if (self::$__signingKeyResource !== false)
openssl_free_key(self::$__signingKeyResource);
openssl_free_key(self::$__signingKeyResource);
}
}


/**
/**
* Set progress function
* Set progress function
*
*
* @param function $func Progress function
* @param function $func Progress function
* @return void
* @return void
*/
*/
public static function setProgressFunction($func = null)
public static function setProgressFunction($func = null)
{
{
self::$progressFunction = $func;
self::$progressFunction = $func;
}
}




/**
/**
* Internal error handler
* Internal error handler
*
*
* @internal Internal error handler
* @internal Internal error handler
* @param string $message Error message
* @param string $message Error message
* @param string $file Filename
* @param string $file Filename
* @param integer $line Line number
* @param integer $line Line number
* @param integer $code Error code
* @param integer $code Error code
* @return void
* @return void
*/
*/
private static function __triggerError($message, $file, $line, $code = 0)
private static function __triggerError($message, $file, $line, $code = 0)
{
{
if (self::$useExceptions)
if (self::$useExceptions)
throw new S3Exception($message, $file, $line, $code);
throw new S3Exception($message, $file, $line, $code);
else
else
trigger_error($message, E_USER_WARNING);
trigger_error($message, E_USER_WARNING);
}
}




/**
/**
* Get a list of buckets
* Get a list of buckets
*
*
* @param boolean $detailed Returns detailed bucket list when true
* @param boolean $detailed Returns detailed bucket list when true
* @return array | false
* @return array | false
*/
*/
public static function listBuckets($detailed = false)
public static function listBuckets($detailed = false)
{
{
$rest = new S3Request('GET', '', '', self::$endpoint);
$rest = new S3Request('GET', '', '', self::$endpoint);
$rest = $rest->getResponse();
$rest = $rest->getResponse();
if ($rest->error === false && $rest->code !== 200)
if ($rest->error === false && $rest->code !== 200)
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
if ($rest->error !== false)
if ($rest->error !== false)
{
{
self::__triggerError(sprintf("S3::listBuckets(): [%s] %s", $rest->error['code'],
self::__triggerError(sprintf("S3::listBuckets(): [%s] %s", $rest->error['code'],
$rest->error['message']), __FILE__, __LINE__);
$rest->error['message']), __FILE__, __LINE__);
return false;
return false;
}
}
$results = array();
$results = array();
if (!isset($rest->body->Buckets)) return $results;
if (!isset($rest->body->Buckets)) return $results;


if ($detailed)
if ($detailed)
{
{
if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName))
if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName))
$results['owner'] = array(
$results['owner'] = array(
'id' => (string)$rest->body->Owner->ID, 'name' => (string)$rest->body->Owner->DisplayName
'id' => (string)$rest->body->Owner->ID, 'name' => (string)$rest->body->Owner->DisplayName
);
);
$results['buckets'] = array();
$results['buckets'] = array();
foreach ($rest->body->Buckets->Bucket as $b)
foreach ($rest->body->Buckets->Bucket as $b)
$results['buckets'][] = array(
$results['buckets'][] = array(
'name' => (string)$b->Name, 'time' => strtotime((string)$b->CreationDate)
'name' => (string)$b->Name, 'time' => strtotime((string)$b->CreationDate)
);
);
} else
} else
foreach ($rest->body->Buckets->Bucket as $b) $results[] = (string)$b->Name;
foreach ($rest->body->Buckets->Bucket as $b) $results[] = (string)$b->Name;


return $results;
return $results;
}
}




/**
/**
* Get contents for a bucket
* Get contents for a bucket
*
*
* If maxKeys is null this method will loop through truncated result sets
* If maxKeys is null this method will loop through truncated result sets
*
*
* @param string $bucket Bucket name
* @param string $bucket Bucket name
* @param string $prefix Prefix
* @param string $prefix Prefix
* @param string $marker Marker (last file listed)
* @param string $marker Marker (last file listed)
* @param string $maxKeys Max keys (maximum number of keys to return)
* @param string $maxKeys Max keys (maximum number of keys to return)
* @param string $delimiter Delimiter
* @param string $delimiter Delimiter
* @param boolean $returnCommonPrefixes Set to true to return CommonPrefixes
* @param boolean $returnCommonPrefixes Set to true to return CommonPrefixes
* @return array | false
* @return array | false
*/
*/
public static function getBucket($bucket, $prefix = null, $marker = null, $maxKeys = null, $delimiter = null, $returnCommonPrefixes = false)
public static function getBucket($bucket, $prefix = null, $marker = null, $maxKeys = null, $delimiter = null, $returnCommonPrefixes = false)
{
{
$rest = new S3Request('GET', $bucket, '', self::$endpoint);
$rest = new S3Request('GET', $bucket, '', self::$endpoint);
if ($maxKeys == 0) $maxKeys = null;
if ($maxKeys == 0) $maxKeys = null;
if ($prefix !== null && $prefix !== '') $rest->setParameter('prefix', $prefix);
if ($prefix !== null && $prefix !== '') $rest->setParameter('prefix', $prefix);
if ($marker !== null && $marker !== '') $rest->setParameter('marker', $marker);
if ($marker !== null && $marker !== '') $rest->setParameter('marker', $marker);
if ($maxKeys !== null && $maxKeys !== '') $rest->setParameter('max-keys', $maxKeys);
if ($maxKeys !== null && $maxKeys !== '') $rest->setParameter('max-keys', $maxKeys);
if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter);
if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter);
else if (!empty(self::$defDelimiter)) $rest->setParameter('delimiter', self::$defDelimiter);
else if (!empty(self::$defDelimiter)) $rest->setParameter('delimiter', self::$defDelimiter);
$response = $rest->getResponse();
$response = $rest->getResponse();
if ($response->error === false && $response->code !== 200)
if ($response->error === false && $response->code !== 200)
$response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status');
$response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status');
if ($response->error !== false)
if ($response->error !== false)
{
{
self::__triggerError(sprintf("S3::getBucket(): [%s] %s",
self::__triggerError(sprintf("S3::getBucket(): [%s] %s",
$response->error['code'], $response->error['message']), __FILE__, __LINE__);
$response->error['code'], $response->error['message']), __FILE__, __LINE__);
return false;
return false;
}
}


$results = array();
$results = array();


$nextMarker = null;
$nextMarker = null;
if (isset($response->body, $response->body->Contents))
if (isset($response->body, $response->body->Contents))
foreach ($response->body->Contents as $c)
foreach ($response->body->Contents as $c)
{
{
$results[(string)$c->Key] = array(
$results[(string)$c->Key] = array(
'name' => (string)$c->Key,
'name' => (string)$c->Key,
'time' => strtotime((string)$c->LastModified),
'time' => strtotime((string)$c->LastModified),
'size' => (int)$c->Size,
'size' => (int)$c->Size,
'hash' => substr((string)$c->ETag, 1, -1)
'hash' => substr((string)$c->ETag, 1, -1)
);
);
$nextMarker = (string)$c->Key;
$nextMarker = (string)$c->Key;
}
}


if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes))
if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes))
foreach ($response->body->CommonPrefixes as $c)
foreach ($response->body->CommonPrefixes as $c)
$results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix);
$results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix);


if (isset($response->body, $response->body->IsTruncated) &&
if (isset($response->body, $response->body->IsTruncated) &&
(string)$response->body->IsTruncated == 'false') return $results;
(string)$response->body->IsTruncated == 'false') return $results;


if (isset($response->body, $response->body->NextMarker))
if (isset($response->body, $response->body->NextMarker))
$nextMarker = (string)$response->body->NextMarker;
$nextMarker = (string)$response->body->NextMarker;


// Loop through truncated results if maxKeys isn't specified
// Loop through truncated results if maxKeys isn't specified
if ($maxKeys == null && $nextMarker !== null && (string)$response->body->IsTruncated == 'true')
if ($maxKeys == null && $nextMarker !== null && (string)$response->body->IsTruncated == 'true')
do
do
{
{
$rest = new S3Request('GET', $bucket, '', self::$endpoint);
$rest = new S3Request('GET', $bucket, '', self::$endpoint);
if ($prefix !== null && $prefix !== '') $rest->setParameter('prefix', $prefix);
if ($prefix !== null && $prefix !== '') $rest->setParameter('prefix', $prefix);
$rest->setParameter('marker', $nextMarker);
$rest->setParameter('marker', $nextMarker);
if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter);
if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter);


if (($response = $rest->getResponse()) == false || $response->code !== 200) break;
if (($response = $rest->getResponse()) == false || $response->code !== 200) break;


if (isset($response->body, $response->body->Contents))
if (isset($response->body, $response->body->Contents))
foreach ($response->body->Contents as $c)
foreach ($response->body->Contents as $c)
{
{
$results[(string)$c->Key] = array(
$results[(string)$c->Key] = array(
'name' => (string)$c->Key,
'name' => (string)$c->Key,
'time' => strtotime((string)$c->LastModified),
'time' => strtotime((string)$c->LastModified),
'size' => (int)$c->Size,
'size' => (int)$c->Size,
'hash' => substr((string)$c->ETag, 1, -1)
'hash' => substr((string)$c->ETag, 1, -1)
);
);
$nextMarker = (string)$c->Key;
$nextMarker = (string)$c->Key;
}
}


if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes))
if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes))
foreach ($response->body->CommonPrefixes as $c)
foreach ($response->body->CommonPrefixes as $c)
$results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix);
$results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix);


if (isset($response->body, $response->body->NextMarker))
if (isset($response->body, $response->body->NextMarker))
$nextMarker = (string)$response->body->NextMarker;
$nextMarker = (string)$response->body->NextMarker;


} while ($response !== false && (string)$response->body->IsTruncated == 'true');
} while ($response !== false && (string)$response->body->IsTruncated == 'true');


return $results;
return $results;
}
}




/**
/**
* Put a bucket
* Put a bucket
*
*
* @param string $bucket Bucket name
* @param string $bucket Bucket name
* @param constant $acl ACL flag
* @param constant $acl ACL flag
* @param string $location Set as "EU" to create buckets hosted in Europe
* @param string $location Set as "EU" to create buckets hosted in Europe
* @return boolean
* @return boolean
*/
*/
public static function putBucket($bucket, $acl = self::ACL_PRIVATE, $location = false)
public static function putBucket($bucket, $acl = self::ACL_PRIVATE, $location = false)
{
{
$rest = new S3Request('PUT', $bucket, '', self::$endpoint);
$rest = new S3Request('PUT', $bucket, '', self::$endpoint);
$rest->setAmzHeader('x-amz-acl', $acl);
$rest->setAmzHeader('x-amz-acl', $acl);


if ($location === false) $location = self::getRegion();
if ($location === false) $location = self::getRegion();


if ($location !== false && $location !== "us-east-1")
if ($location !== false && $location !== "us-east-1")
{
{
$dom = new DOMDocument;
$dom = new DOMDocument;
$createBucketConfiguration = $dom->createElement('CreateBucketConfiguration');
$createBucketConfiguration = $dom->createElement('CreateBucketConfiguration');
$locationConstraint = $dom->createElement('LocationConstraint', $location);
$locationConstraint = $dom->createElement('LocationConstraint', $location);
$createBucketConfiguration->appendChild($locationConstraint);
$createBucketConfiguration->appendChild($locationConstraint);
$dom->appendChild($createBucketConfiguration);
$dom->appendChild($createBucketConfiguration);
$rest->data = $dom->saveXML();
$rest->data = $dom->saveXML();
$rest->size = strlen($rest->data);
$rest->size = strlen($rest->data);
$rest->setHeader('Content-Type', 'application/xml');
$rest->setHeader('Content-Type', 'application/xml');
}
}
$rest = $rest->getResponse();
$rest = $rest->getResponse();


if ($rest->error === false && $rest->code !== 200)
if ($rest->error === false && $rest->code !== 200)
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
if ($rest->error !== false)
if ($rest->error !== false)
{
{
self::__triggerError(sprintf("S3::putBucket({$bucket}, {$acl}, {$location}): [%s] %s",
self::__triggerError(sprintf("S3::putBucket({$bucket}, {$acl}, {$location}): [%s] %s",
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
return false;
return false;
}
}
return true;
return true;
}
}




/**
/**
* Delete an empty bucket
* Delete an empty bucket
*
*
* @param string $bucket Bucket name
* @param string $bucket Bucket name
* @return boolean
* @return boolean
*/
*/
public static function deleteBucket($bucket)
public static function deleteBucket($bucket)
{
{
$rest = new S3Request('DELETE', $bucket, '', self::$endpoint);
$rest = new S3Request('DELETE', $bucket, '', self::$endpoint);
$rest = $rest->getResponse();
$rest = $rest->getResponse();
if ($rest->error === false && $rest->code !== 204)
if ($rest->error === false && $rest->code !== 204)
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
if ($rest->error !== false)
if ($rest->error !== false)
{
{
self::__triggerError(sprintf("S3::deleteBucket({$bucket}): [%s] %s",
self::__triggerError(sprintf("S3::deleteBucket({$bucket}): [%s] %s",
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
return false;
return false;
}
}
return true;
return true;
}
}




/**
/**
* Create input info array for putObject()
* Create input info array for putObject()
*
*
* @param string $file Input file
* @param string $file Input file
* @param mixed $md5sum Use MD5 hash (supply a string if you want to use your own)
* @param mixed $md5sum Use MD5 hash (supply a string if you want to use your own)
* @return array | false
* @return array | false
*/
*/
public static function inputFile($file, $md5sum = true)
public static function inputFile($file, $md5sum = true)
{
{
if (!file_exists($file) || !is_file($file) || !is_readable($file))
if (!file_exists($file) || !is_file($file) || !is_readable($file))
{
{
self::__triggerError('S3::inputFile(): Unable to open input file: '.$file, __FILE__, __LINE__);
self::__triggerError('S3::inputFile(): Unable to open input file: '.$file, __FILE__, __LINE__);
return false;
return false;
}
}
clearstatcache(false, $file);
clearstatcache(false, $file);
return array('file' => $file, 'size' => filesize($file), 'md5sum' => $md5sum !== false ?
return array('file' => $file, 'size' => filesize($file), 'md5sum' => $md5sum !== false ?
(is_string($md5sum) ? $md5sum : base64_encode(md5_file($file, true))) : '', 'sha256sum' => hash_file('sha256', $file));
(is_string($md5sum) ? $md5sum : base64_encode(md5_file($file, true))) : '', 'sha256sum' => hash_file('sha256', $file));
}
}




/**
/**
* Create input array info for putObject() with a resource
* Create input array info for putObject() with a resource
*
*
* @param string $resource Input resource to read from
* @param string $resource Input resource to read from
* @param integer $bufferSize Input byte size
* @param integer $bufferSize Input byte size
* @param string $md5sum MD5 hash to send (optional)
* @param string $md5sum MD5 hash to send (optional)
* @return array | false
* @return array | false
*/
*/
public static function inputResource(&$resource, $bufferSize = false, $md5sum = '')
public static function inputResource(&$resource, $bufferSize = false, $md5sum = '')
{
{
if (!is_resource($resource) || (int)$bufferSize < 0)
if (!is_resource($resource) || (int)$bufferSize < 0)
{
{
self::__triggerError('S3::inputResource(): Invalid resource or buffer size', __FILE__, __LINE__);
self::__triggerError('S3::inputResource(): Invalid resource or buffer size', __FILE__, __LINE__);
return false;
return false;
}
}


// Try to figure out the bytesize
// Try to figure out the bytesize
if ($bufferSize === false)
if ($bufferSize === false)
{
{
if (fseek($resource, 0, SEEK_END) < 0 || ($bufferSize = ftell($resource)) === false)
if (fseek($resource, 0, SEEK_END) < 0 || ($bufferSize = ftell($resource)) === false)
{
{
self::__triggerError('S3::inputResource(): Unable to obtain resource size', __FILE__, __LINE__);
self::__triggerError('S3::inputResource(): Unable to obtain resource size', __FILE__, __LINE__);
return false;
return false;
}
}
fseek($resource, 0);
fseek($resource, 0);
}
}


$input = array('size' => $bufferSize, 'md5sum' => $md5sum);
$input = array('size' => $bufferSize, 'md5sum' => $md5sum);
$input['fp'] =& $resource;
$input['fp'] =& $resource;
return $input;
return $input;
}
}




/**
/**
* Put an object
* Put an object
*
*
* @param mixed $input Input data
* @param mixed $input Input data
* @param string $bucket Bucket name
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param string $uri Object URI
* @param constant $acl ACL constant
* @param constant $acl ACL constant
* @param array $metaHeaders Array of x-amz-meta-* headers
* @param array $metaHeaders Array of x-amz-meta-* headers
* @param array $requestHeaders Array of request headers or content type as a string
* @param array $requestHeaders Array of request headers or content type as a string
* @param constant $storageClass Storage class constant
* @param constant $storageClass Storage class constant
* @param constant $serverSideEncryption Server-side encryption
* @param constant $serverSideEncryption Server-side encryption
* @return boolean
* @return boolean
*/
*/
public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD, $serverSideEncryption = self::SSE_NONE)
public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD, $serverSideEncryption = self::SSE_NONE)
{
{
if ($input === false) return false;
if ($input === false) return false;
$rest = new S3Request('PUT', $bucket, $uri, self::$endpoint);
$rest = new S3Request('PUT', $bucket, $uri, self::$endpoint);


if (!is_array($input)) $input = array(
if (!is_array($input)) $input = array(
'data' => $input, 'size' => strlen($input),
'data' => $input, 'size' => strlen($input),
'md5sum' => base64_encode(md5($input, true)),
'md5sum' => base64_encode(md5($input, true)),
'sha256sum' => hash('sha256', $input)
'sha256sum' => hash('sha256', $input)
);
);


// Data
// Data
if (isset($input['fp']))
if (isset($input['fp']))
$rest->fp =& $input['fp'];
$rest->fp =& $input['fp'];
elseif (isset($input['file']))
elseif (isset($input['file']))
$rest->fp = @fopen($input['file'], 'rb');
$rest->fp = @fopen($input['file'], 'rb');
elseif (isset($input['data']))
elseif (isset($input['data']))
$rest->data = $input['data'];
$rest->data = $input['data'];


// Content-Length (required)
// Content-Length (required)
if (isset($input['size']) && $input['size'] >= 0)
if (isset($input['size']) && $input['size'] >= 0)
$rest->size = $input['size'];
$rest->size = $input['size'];
else {
else {
if (isset($input['file'])) {
if (isset($input['file'])) {
clearstatcache(false, $input['file']);
clearstatcache(false, $input['file']);
$rest->size = filesize($input['file']);
$rest->size = filesize($input['file']);
}
}
elseif (isset($input['data']))
elseif (isset($input['data']))
$rest->size = strlen($input['data']);
$rest->size = strlen($input['data']);
}
}


// Custom request headers (Content-Type, Content-Disposition, Content-Encoding)
// Custom request headers (Content-Type, Content-Disposition, Content-Encoding)
if (is_array($requestHeaders))
if (is_array($requestHeaders))
foreach ($requestHeaders as $h => $v)
foreach ($requestHeaders as $h => $v)
strpos($h, 'x-amz-') === 0 ? $rest->setAmzHeader($h, $v) : $rest->setHeader($h, $v);
strpos($h, 'x-amz-') === 0 ? $rest->setAmzHeader($h, $v) : $rest->setHeader($h, $v);
elseif (is_string($requestHeaders)) // Support for legacy contentType parameter
elseif (is_string($requestHeaders)) // Support for legacy contentType parameter
$input['type'] = $requestHeaders;
$input['type'] = $requestHeaders;


// Content-Type
// Content-Type
if (!isset($input['type']))
if (!isset($input['type']))
{
{
if (isset($requestHeaders['Content-Type']))
if (isset($requestHeaders['Content-Type']))
$input['type'] =& $requestHeaders['Content-Type'];
$input['type'] =& $requestHeaders['Content-Type'];
elseif (isset($input['file']))
elseif (isset($input['file']))
$input['type'] = self::__getMIMEType($input['file']);
$input['type'] = self::__getMIMEType($input['file']);
else
else
$input['type'] = 'application/octet-stream';
$input['type'] = 'application/octet-stream';
}
}


if ($storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class
if ($storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class
$rest->setAmzHeader('x-amz-storage-class', $storageClass);
$rest->setAmzHeader('x-amz-storage-class', $storageClass);


if ($serverSideEncryption !== self::SSE_NONE) // Server-side encryption
if ($serverSideEncryption !== self::SSE_NONE) // Server-side encryption
$rest->setAmzHeader('x-amz-server-side-encryption', $serverSideEncryption);
$rest->setAmzHeader('x-amz-server-side-encryption', $serverSideEncryption);


// We need to post with Content-Length and Content-Type, MD5 is optional
// We need to post with Content-Length and Content-Type, MD5 is optional
if ($rest->size >= 0 && ($rest->fp !== false || $rest->data !== false))
if ($rest->size >= 0 && ($rest->fp !== false || $rest->data !== false))
{
{
$rest->setHeader('Content-Type', $input['type']);
$rest->setHeader('Content-Type', $input['type']);
if (isset($input['md5sum'])) $rest->setHeader('Content-MD5', $input['md5sum']);
if (isset($input['md5sum'])) $rest->setHeader('Content-MD5', $input['md5sum']);


if (isset($input['sha256sum'])) $rest->setAmzHeader('x-amz-content-sha256', $input['sha256sum']);
if (isset($input['sha256sum'])) $rest->setAmzHeader('x-amz-content-sha256', $input['sha256sum']);


$rest->setAmzHeader('x-amz-acl', $acl);
$rest->setAmzHeader('x-amz-acl', $acl);
foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
$rest->getResponse();
$rest->getResponse();
} else
} else
$rest->response->error = array('code' => 0, 'message' => 'Missing input parameters');
$rest->response->error = array('code' => 0, 'message' => 'Missing input parameters');


if ($rest->response->error === false && $rest->response->code !== 200)
if ($rest->response->error === false && $rest->response->code !== 200)
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
if ($rest->response->error !== false)
if ($rest->response->error !== false)
{
{
self::__triggerError(sprintf("S3::putObject(): [%s] %s",
self::__triggerError(sprintf("S3::putObject(): [%s] %s",
$rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__);
$rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__);
return false;
return false;
}
}
return true;
return true;
}
}




/**
/**
* Put an object from a file (legacy function)
* Put an object from a file (legacy function)
*
*
* @param string $file Input file path
* @param string $file Input file path
* @param string $bucket Bucket name
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param string $uri Object URI
* @param constant $acl ACL constant
* @param constant $acl ACL constant
* @param array $metaHeaders Array of x-amz-meta-* headers
* @param array $metaHeaders Array of x-amz-meta-* headers
* @param string $contentType Content type
* @param string $contentType Content type
* @return boolean
* @return boolean
*/
*/
public static function putObjectFile($file, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = null)
public static function putObjectFile($file, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = null)
{
{
return self::putObject(self::inputFile($file), $bucket, $uri, $acl, $metaHeaders, $contentType);
return self::putObject(self::inputFile($file), $bucket, $uri, $acl, $metaHeaders, $contentType);
}
}




/**
/**
* Put an object from a string (legacy function)
* Put an object from a string (legacy function)
*
*
* @param string $string Input data
* @param string $string Input data
* @param string $bucket Bucket name
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param string $uri Object URI
* @param constant $acl ACL constant
* @param constant $acl ACL constant
* @param array $metaHeaders Array of x-amz-meta-* headers
* @param array $metaHeaders Array of x-amz-meta-* headers
* @param string $contentType Content type
* @param string $contentType Content type
* @return boolean
* @return boolean
*/
*/
public static function putObjectString($string, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = 'text/plain')
public static function putObjectString($string, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = 'text/plain')
{
{
return self::putObject($string, $bucket, $uri, $acl, $metaHeaders, $contentType);
return self::putObject($string, $bucket, $uri, $acl, $metaHeaders, $contentType);
}
}




/**
/**
* Get an object
* Get an object
*
*
* @param string $bucket Bucket name
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param string $uri Object URI
* @param mixed $saveTo Filename or resource to write to
* @param mixed $saveTo Filename or resource to write to
* @return mixed
* @return mixed
*/
*/
public static function getObject($bucket, $uri, $saveTo = false)
public static function getObject($bucket, $uri, $saveTo = false)
{
{
$rest = new S3Request('GET', $bucket, $uri, self::$endpoint);
$rest = new S3Request('GET', $bucket, $uri, self::$endpoint);
if ($saveTo !== false)
if ($saveTo !== false)
{
{
if (is_resource($saveTo))
if (is_resource($saveTo))
$rest->fp =& $saveTo;
$rest->fp =& $saveTo;
else
else
if (($rest->fp = @fopen($saveTo, 'wb')) !== false)
if (($rest->fp = @fopen($saveTo, 'wb')) !== false)
$rest->file = realpath($saveTo);
$rest->file = realpath($saveTo);
else
else
$rest->response->error = array('code' => 0, 'message' => 'Unable to open save file for writing: '.$saveTo);
$rest->response->error = array('code' => 0, 'message' => 'Unable to open save file for writing: '.$saveTo);
}
}
if ($rest->response->error === false) $rest->getResponse();
if ($rest->response->error === false) $rest->getResponse();


if ($rest->response->error === false && $rest->response->code !== 200)
if ($rest->response->error === false && $rest->response->code !== 200)
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
if ($rest->response->error !== false)
if ($rest->response->error !== false)
{
{
self::__triggerError(sprintf("S3::getObject({$bucket}, {$uri}): [%s] %s",
self::__triggerError(sprintf("S3::getObject({$bucket}, {$uri}): [%s] %s",
$rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__);
$rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__);
return false;
return false;
}
}
return $rest->response;
return $rest->response;
}
}




/**
/**
* Get object information
* Get object information
*
*
* @param string $bucket Bucket name
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param string $uri Object URI
* @param boolean $returnInfo Return response information
* @param boolean $returnInfo Return response information
* @return mixed | false
* @return mixed | false
*/
*/
public static function getObjectInfo($bucket, $uri, $returnInfo = true)
public static function getObjectInfo($bucket, $uri, $returnInfo = true)
{
{
$rest = new S3Request('HEAD', $bucket, $uri, self::$endpoint);
$rest = new S3Request('HEAD', $bucket, $uri, self::$endpoint);
$rest = $rest->getResponse();
$rest = $rest->getResponse();
if ($rest->error === false && ($rest->code !== 200 && $rest->code !== 404))
if ($rest->error === false && ($rest->code !== 200 && $rest->code !== 404))
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
if ($rest->error !== false)
if ($rest->error !== false)
{
{
self::__triggerError(sprintf("S3::getObjectInfo({$bucket}, {$uri}): [%s] %s",
self::__triggerError(sprintf("S3::getObjectInfo({$bucket}, {$uri}): [%s] %s",
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
return false;
return false;
}
}
return $rest->code == 200 ? $returnInfo ? $rest->headers : true : false;
return $rest->code == 200 ? $returnInfo ? $rest->headers : true : false;
}
}




/**
/**
* Copy an object
* Copy an object
*
*
* @param string $srcBucket Source bucket name
* @param string $srcBucket Source bucket name
* @param string $srcUri Source object URI
* @param string $srcUri Source object URI
* @param string $bucket Destination bucket name
* @param string $bucket Destination bucket name
* @param string $uri Destination object URI
* @param string $uri Destination object URI
* @
* @