|
|
|
@@ -32,7 +32,7 @@
|
|
|
|
|
* Amazon S3 PHP class
|
|
|
|
|
*
|
|
|
|
|
* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
|
|
|
|
|
* @version 0.5.1-dev
|
|
|
|
|
* @version 0.5.1
|
|
|
|
|
*/
|
|
|
|
|
class S3
|
|
|
|
|
{
|
|
|
|
@@ -56,7 +56,7 @@ class S3
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
private static $__accessKey = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* AWS Secret Key
|
|
|
|
|
*
|
|
|
|
@@ -65,7 +65,7 @@ class S3
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
private static $__secretKey = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SSL Client key
|
|
|
|
|
*
|
|
|
|
@@ -74,7 +74,15 @@ class S3
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
private static $__sslKey = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Default delimiter to be used, for example while getBucket().
|
|
|
|
|
* @var string
|
|
|
|
|
* @access public
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
public static $defDelimiter = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* AWS URI
|
|
|
|
|
*
|
|
|
|
@@ -83,7 +91,7 @@ class S3
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
public static $endpoint = 's3.amazonaws.com';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Proxy information
|
|
|
|
|
*
|
|
|
|
@@ -92,7 +100,7 @@ class S3
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
public static $proxy = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Connect using SSL?
|
|
|
|
|
*
|
|
|
|
@@ -101,7 +109,7 @@ class S3
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
public static $useSSL = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Use SSL validation?
|
|
|
|
|
*
|
|
|
|
@@ -110,7 +118,16 @@ class S3
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
public static $useSSLValidation = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Use SSL version
|
|
|
|
|
*
|
|
|
|
|
* @var const
|
|
|
|
|
* @access public
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
public static $useSSLVersion = CURL_SSLVERSION_TLSv1;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Use PHP exceptions?
|
|
|
|
|
*
|
|
|
|
@@ -202,6 +219,7 @@ class S3
|
|
|
|
|
self::$endpoint = $host;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set AWS access key and secret key
|
|
|
|
|
*
|
|
|
|
@@ -416,6 +434,7 @@ class S3
|
|
|
|
|
if ($marker !== null && $marker !== '') $rest->setParameter('marker', $marker);
|
|
|
|
|
if ($maxKeys !== null && $maxKeys !== '') $rest->setParameter('max-keys', $maxKeys);
|
|
|
|
|
if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter);
|
|
|
|
|
else if (!empty(self::$defDelimiter)) $rest->setParameter('delimiter', self::$defDelimiter);
|
|
|
|
|
$response = $rest->getResponse();
|
|
|
|
|
if ($response->error === false && $response->code !== 200)
|
|
|
|
|
$response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status');
|
|
|
|
@@ -561,6 +580,7 @@ class S3
|
|
|
|
|
self::__triggerError('S3::inputFile(): Unable to open input file: '.$file, __FILE__, __LINE__);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
clearstatcache(false, $file);
|
|
|
|
|
return array('file' => $file, 'size' => filesize($file), 'md5sum' => $md5sum !== false ?
|
|
|
|
|
(is_string($md5sum) ? $md5sum : base64_encode(md5_file($file, true))) : '');
|
|
|
|
|
}
|
|
|
|
@@ -634,15 +654,18 @@ class S3
|
|
|
|
|
if (isset($input['size']) && $input['size'] >= 0)
|
|
|
|
|
$rest->size = $input['size'];
|
|
|
|
|
else {
|
|
|
|
|
if (isset($input['file']))
|
|
|
|
|
if (isset($input['file'])) {
|
|
|
|
|
clearstatcache(false, $input['file']);
|
|
|
|
|
$rest->size = filesize($input['file']);
|
|
|
|
|
}
|
|
|
|
|
elseif (isset($input['data']))
|
|
|
|
|
$rest->size = strlen($input['data']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Custom request headers (Content-Type, Content-Disposition, Content-Encoding)
|
|
|
|
|
if (is_array($requestHeaders))
|
|
|
|
|
foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
|
|
|
|
|
foreach ($requestHeaders as $h => $v)
|
|
|
|
|
strpos($h, 'x-amz-') === 0 ? $rest->setAmzHeader($h, $v) : $rest->setHeader($h, $v);
|
|
|
|
|
elseif (is_string($requestHeaders)) // Support for legacy contentType parameter
|
|
|
|
|
$input['type'] = $requestHeaders;
|
|
|
|
|
|
|
|
|
@@ -797,7 +820,8 @@ class S3
|
|
|
|
|
{
|
|
|
|
|
$rest = new S3Request('PUT', $bucket, $uri, self::$endpoint);
|
|
|
|
|
$rest->setHeader('Content-Length', 0);
|
|
|
|
|
foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
|
|
|
|
|
foreach ($requestHeaders as $h => $v)
|
|
|
|
|
strpos($h, 'x-amz-') === 0 ? $rest->setAmzHeader($h, $v) : $rest->setHeader($h, $v);
|
|
|
|
|
foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
|
|
|
|
|
if ($storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class
|
|
|
|
|
$rest->setAmzHeader('x-amz-storage-class', $storageClass);
|
|
|
|
@@ -2117,6 +2141,9 @@ final class S3Request
|
|
|
|
|
|
|
|
|
|
if (S3::$useSSL)
|
|
|
|
|
{
|
|
|
|
|
// Set protocol version
|
|
|
|
|
curl_setopt($curl, CURLOPT_SSLVERSION, S3::$useSSLVersion);
|
|
|
|
|
|
|
|
|
|
// SSL Validation can now be optional for those with broken OpenSSL installations
|
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, S3::$useSSLValidation ? 2 : 0);
|
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, S3::$useSSLValidation ? 1 : 0);
|
|
|
|
@@ -2292,6 +2319,7 @@ final class S3Request
|
|
|
|
|
private function __dnsBucketName($bucket)
|
|
|
|
|
{
|
|
|
|
|
if (strlen($bucket) > 63 || preg_match("/[^a-z0-9\.-]/", $bucket) > 0) return false;
|
|
|
|
|
if (S3::$useSSL && strstr($bucket, '.') !== false) return false;
|
|
|
|
|
if (strstr($bucket, '-.') !== false) return false;
|
|
|
|
|
if (strstr($bucket, '..') !== false) return false;
|
|
|
|
|
if (!preg_match("/^[0-9a-z]/", $bucket)) return false;
|
|
|
|
|