本文整理汇总了PHP中S3Request::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP S3Request::getResponse方法的具体用法?PHP S3Request::getResponse怎么用?PHP S3Request::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类S3Request
的用法示例。
在下文中一共展示了S3Request::getResponse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getObject
/**
* Get an object
*
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param mixed $saveTo Filename or resource to write to
* @return mixed
*/
public static function getObject($bucket, $uri, $saveTo = false)
{
$rest = new S3Request('GET', $bucket, $uri, self::$endpoint);
if ($saveTo !== false) {
if (is_resource($saveTo)) {
$rest->fp =& $saveTo;
} else {
if (($rest->fp = @fopen($saveTo, 'wb')) !== false) {
$rest->file = realpath($saveTo);
} else {
$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->response->code !== 200) {
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
}
if ($rest->response->error !== false) {
self::__triggerError(sprintf("S3::getObject({$bucket}, {$uri}): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__);
return false;
}
return $rest->response;
}
示例2: getObject
/**
* Get an object
*
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param mixed $saveTo Filename or resource to write to
* @return mixed
*/
public static function getObject($bucket, $uri, $saveTo = false)
{
$rest = new S3Request('GET', $bucket, $uri);
if ($saveTo !== false) {
if (is_resource($saveTo)) {
$rest->fp = $saveTo;
} else {
if (($rest->fp = @fopen($saveTo, 'wb')) !== false) {
$rest->file = realpath($saveTo);
} else {
$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->response->code !== 200) {
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
}
if ($rest->response->error !== false) {
if ($rest->response->error['code'] != 'NoSuchKey') {
trigger_error(sprintf("S3::getObject({$bucket}, {$uri}): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), E_USER_WARNING);
}
return false;
}
return $rest->response;
}
示例3: getObject
public static function getObject($bucket, $uri, $saveTo = false)
{
$rest = new S3Request('GET', $bucket, $uri);
if ($saveTo !== false) {
if (($rest->fp = @fopen($saveTo, 'wb')) !== false) {
$rest->file = realpath($saveTo);
}
}
throw new Exception(sprintf("S3::getObject(%s, %s): [%s] %s", $bucket, $uri, 0, 'Unable to open save file for writing: ' . $saveTo));
$rest->getResponse();
if ($rest->response->error !== false || $rest->response->code !== 200) {
throw new Exception(sprintf("S3::getObject(%s, %s): [%s] %s", $bucket, $uri, $rest->response->code, 'Unexpected HTTP status'));
}
return $rest->response;
}
示例4: getObjectInfo
/**
* Get object information
*
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param boolean $returnInfo Return response information
* @return mixed | false
*/
public static function getObjectInfo($bucket, $uri, $returnInfo = true)
{
$request = new S3Request('HEAD', $bucket, $uri);
$response = $request->getResponse();
if ($response->error !== false) {
throw new S3Exception($response->error['message'], $response->error['code']);
}
if ($response->code !== 200 && $response->code !== 404) {
throw new S3Exception('Unexpected HTTP status', $response->code);
}
if ($response->code == 200) {
return $returnInfo ? $response->headers : true;
}
return false;
}
示例5: getObject
/**
* Get an object
*
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param mixed $saveTo Filename or resource to write to
* @return mixed
*/
public static function getObject($bucket, $uri, $saveTo = false, $from = null, $to = null)
{
$rest = new S3Request('GET', $bucket, $uri);
if ($saveTo !== false) {
if (is_resource($saveTo)) {
$rest->fp =& $saveTo;
} else {
if (($rest->fp = @fopen($saveTo, 'wb')) !== false) {
$rest->file = realpath($saveTo);
} else {
$rest->response->error = array('code' => 0, 'message' => 'Unable to open save file for writing: ' . $saveTo);
}
}
}
if ($rest->response->error === false) {
// Set the range header
if (!is_null($from) && !is_null($to)) {
$rest->setHeader('Range', "bytes={$from}-{$to}");
}
$rest->getResponse();
}
if ($rest->response->error === false && ($rest->response->code !== 200 && $rest->response->code !== 206)) {
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
}
if ($rest->response->error !== false) {
throw new S3Exception(sprintf("S3::getObject({$bucket}, {$uri}): [%s] %s", $rest->response->error['code'], $rest->response->error['message']));
return false;
}
return $rest->response;
}
示例6: getObject
/**
* Get an object
*
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param mixed $saveTo Filename or resource to write to
* @return mixed
*/
public function getObject($bucket, $uri, $saveTo = false)
{
$rest = new S3Request($this->accessKey, $this->secretKey, $this->useSSL, 'GET', $bucket, $uri);
if ($saveTo !== false) {
if (is_resource($saveTo)) {
$rest->fp =& $saveTo;
} else {
if (($rest->fp = @fopen($saveTo, 'wb')) == false) {
$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->response->code !== 200) {
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
}
if ($rest->response->error !== false) {
throw new AWSException(sprintf("S3::getObject({$bucket}, {$uri}): [%s] %s", $rest->response->error['code'], $rest->response->error['message']));
}
$rest->file = realpath($saveTo);
return $rest->response;
}
示例7: amazon_upload_file
private function amazon_upload_file($data)
{
$response =& $this->request->post['last'];
$s3 =& $data['s3'];
$buckets = $s3->listBuckets();
$cssjs_browser_cache = 0;
$images_browser_cache = 0;
if (getNitroPersistence('BrowserCache.Enabled') && getNitroPersistence('BrowserCache.Headers.Pages.Expires')) {
if (getNitroPersistence('BrowserCache.CSSJS.Period')) {
switch (getNitroPersistence('BrowserCache.CSSJS.Period')) {
case '1 week':
$cssjs_browser_cache = 7 * 24 * 3600;
break;
case '1 month':
$cssjs_browser_cache = 30 * 24 * 3600;
break;
case '6 months':
$cssjs_browser_cache = 6 * 30 * 24 * 3600;
break;
case '1 year':
$cssjs_browser_cache = 365 * 24 * 3600;
break;
default:
$cssjs_browser_cache = 0;
}
}
if (getNitroPersistence('BrowserCache.Images.Period')) {
switch (getNitroPersistence('BrowserCache.Images.Period')) {
case '1 week':
$images_browser_cache = 7 * 24 * 3600;
break;
case '1 month':
$images_browser_cache = 30 * 24 * 3600;
break;
case '6 months':
$images_browser_cache = 6 * 30 * 24 * 3600;
break;
case '1 year':
$images_browser_cache = 365 * 24 * 3600;
break;
default:
$images_browser_cache = 0;
}
}
}
$source = $data['file']['realpath'];
$destination = $data['file']['file'];
$ext = strtolower(pathinfo($source, PATHINFO_EXTENSION));
if (getNitroPersistence('CDNAmazon.SyncCSS') && in_array($ext, unserialize(NITRO_EXTENSIONS_CSS))) {
$bucket = getNitroPersistence('CDNAmazon.CSSBucket');
if (is_array($buckets) && in_array($bucket, $buckets)) {
$compress = getNitroPersistence('Compress.CSS') && getNitroPersistence('Compress.CSSLevel') ? (int) getNitroPersistence('Compress.CSSLevel') : false;
$cache_time = $cssjs_browser_cache;
} else {
throw new Exception('The CSS bucket does not exist. Please create it.');
}
}
if (getNitroPersistence('CDNAmazon.SyncJavaScript') && in_array($ext, unserialize(NITRO_EXTENSIONS_JS))) {
$bucket = getNitroPersistence('CDNAmazon.JavaScriptBucket');
if (is_array($buckets) && in_array($bucket, $buckets)) {
$compress = getNitroPersistence('Compress.JS') && getNitroPersistence('Compress.JSLevel') ? (int) getNitroPersistence('Compress.JSLevel') : false;
$cache_time = $cssjs_browser_cache;
} else {
throw new Exception('The JS bucket does not exist. Please create it.');
}
}
if (getNitroPersistence('CDNAmazon.SyncImages') && in_array($ext, unserialize(NITRO_EXTENSIONS_IMG))) {
$bucket = getNitroPersistence('CDNAmazon.ImageBucket');
if (is_array($buckets) && in_array($bucket, $buckets)) {
$compress = false;
$cache_time = $images_browser_cache;
} else {
throw new Exception('The images bucket does not exist. Please create it.');
}
}
if (empty($bucket)) {
return;
}
$req = new S3Request('HEAD', $bucket, $destination);
$res = $req->getResponse();
$to_upload = $res->code != 200 || $res->code == 200 && ((!empty($compress) xor !empty($res->headers['x-amz-meta-compressed'])) || (!empty($cache_time) xor !empty($res->headers['x-amz-meta-expires-time'])) || !empty($cache_time) && !empty($res->headers['x-amz-meta-expires-time']) && (int) $cache_time != $res->headers['x-amz-meta-expires-time']);
if ($to_upload) {
$headers = array();
$meta_headers = array();
if (!empty($cache_time)) {
$headers['Expires'] = gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $cache_time);
$meta_headers['expires-time'] = $cache_time;
}
switch ($ext) {
case 'css':
$headers['Content-Type'] = 'text/css';
break;
case 'js':
$headers['Content-Type'] = 'text/javascript';
break;
}
if (!empty($compress) && is_readable($source) && !empty($headers['Content-Type'])) {
$headers['Content-Encoding'] = 'gzip';
$meta_headers['compressed'] = '1';
$contents = gzencode(file_get_contents($source), $compress);
//.........这里部分代码省略.........
示例8: getObject
/**
* Get an object
*
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param mixed &$saveTo Filename or resource to write to
* @return mixed
*/
public static function getObject($bucket = '', $uri = '', $saveTo = false)
{
$rest = new S3Request('GET', $bucket, $uri);
if ($saveTo !== false) {
if (is_resource($saveTo)) {
$rest->fp =& $saveTo;
} else {
if (($rest->fp = @fopen($saveTo, 'wb')) == false) {
$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->response->code !== 200) {
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
}
if ($rest->response->error !== false) {
throw new S3Exception($rest->response->error['code'], "Could not get object {$bucket} / {$uri}: " . $rest->response->error['message']);
return false;
}
$rest->file = realpath($saveTo);
return $rest->response;
}