getResponse() 공개 메소드

Get the S3 response
public getResponse ( ) : object | false
리턴 object | false | false
예제 #1
0
 /**
  * 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
0
파일: S3.php 프로젝트: rogeriocc/fabrik
 /**
  * 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
0
파일: S3.php 프로젝트: comdan66/TaipeiTowns
 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
0
 /**
  * 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
0
 /**
  * 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
0
파일: s3.php 프로젝트: nikels/HeavyMetal
 /**
  * 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
0
 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);
             $temp_file = tempnam(sys_get_temp_dir(), 'Nitro');
             $temp_handle = fopen($temp_file, "w");
             if (empty($temp_handle) || !fwrite($temp_handle, $contents)) {
                 throw new Exception('There was a problem writing to ' . $temp_file);
             }
             fclose($temp_handle);
             $source = $temp_file;
         }
         if ($s3->putObject($s3->inputFile($source), $bucket, $destination, S3::ACL_PUBLIC_READ, $meta_headers, $headers)) {
             if (!empty($temp_file)) {
                 unlink($temp_file);
                 unset($temp_file);
             }
         } else {
             throw new Exception('Could not upload ' . $destination);
         }
     }
 }
예제 #8
0
파일: S3.php 프로젝트: pneff/binarypool
 /**
  * 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;
 }