Exemplo n.º 1
0
 /**
  * Get the response
  *
  * @return object | false
  */
 public function getResponse()
 {
     if ($this->expires) {
         $this->parameters['Expires'] = gmdate('c');
     } else {
         $this->parameters['Timestamp'] = gmdate('c');
     }
     $params = array();
     foreach ($this->parameters as $var => $value) {
         $params[] = $var . '=' . rawurlencode($value);
     }
     sort($params, SORT_STRING);
     $query = implode('&', $params);
     $strtosign = $this->verb . "\n" . $this->url . "\n/" . $this->queue . "\n" . $query;
     $query .= '&Signature=' . rawurlencode(SQS::__getSignature($strtosign));
     $ssl = SQS::$useSSL && extension_loaded('openssl');
     $url = ($ssl ? 'https://' : 'http://') . $this->url . '/' . $this->queue . '?' . $query;
     // Basic setup
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_USERAGENT, 'SQS/php');
     if (SQS::$useSSL) {
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, SQS::$verifyHost);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, SQS::$verifyPeer);
     }
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_HEADER, false);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
     curl_setopt($curl, CURLOPT_WRITEFUNCTION, array(&$this, '__responseWriteCallback'));
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
     // Request types
     switch ($this->verb) {
         case 'GET':
             break;
         case 'PUT':
         case 'POST':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->verb);
             $headers[] = 'Content-Type: application/x-www-form-urlencoded';
             break;
         case 'HEAD':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'HEAD');
             curl_setopt($curl, CURLOPT_NOBODY, true);
             break;
         case 'DELETE':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
             break;
         default:
             break;
     }
     if (count($headers) > 0) {
         curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     }
     // Execute, grab errors
     if (curl_exec($curl)) {
         $this->response->code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     } else {
         $this->response->error = array('curl' => true, 'code' => curl_errno($curl), 'message' => curl_error($curl), 'resource' => $this->resource);
     }
     @curl_close($curl);
     // Parse body into XML
     if ($this->response->error === false && isset($this->response->body)) {
         $this->response->body = simplexml_load_string($this->response->body);
         // Grab SQS errors
         if (!in_array($this->response->code, array(200, 204)) && isset($this->response->body->Error)) {
             $this->response->error = array('curl' => false, 'Type' => (string) $this->response->body->Error->Type, 'Code' => (string) $this->response->body->Error->Code, 'Message' => (string) $this->response->body->Error->Message, 'Detail' => (string) $this->response->body->Error->Detail);
             unset($this->response->body);
         }
     }
     return $this->response;
 }
Exemplo n.º 2
0
if (!class_exists('S3')) {
    require_once 'S3.php';
}
//AWS access info
if (!defined('awsAccessKey')) {
    define('awsAccessKey', getenv('S3_KEY'));
}
if (!defined('awsSecretKey')) {
    define('awsSecretKey', getenv('S3_SECRET'));
}
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
// 引入 SQS class 並 initiate
// $sqs = new SQS('Access Key Here', 'Secret Key Here');
require_once 'sqs.php';
$sqs = new SQS(awsAccessKey, awsSecretKey);
// 先設定好 queue 的位置
$input_queue = "https://sqs.us-west-2.amazonaws.com/500101126759/input";
/******
	上傳檔案到 S3(等待 process 程式處理)
******/
/* 外部 S3 class 設定 */
/* 上傳表單 post 回同一頁,判斷如果有上傳把檔案接回來 */
/* 判斷附檔名,若為常見圖檔(jpg, png, gif)則將檔案內容存進 cache 並上傳到 S3 */
/* 否則跳出不支援提示 */
if (isset($_POST['Submit'])) {
    //retreive post variables
    $fileName = $_FILES['theFile']['name'];
    $fileTempName = $_FILES['theFile']['tmp_name'];
    $path_ext = pathinfo($fileName, PATHINFO_EXTENSION);
    // get filename extension
Exemplo n.º 3
0
 public function __construct()
 {
     parent::__construct(Kohana::config('amazon.account.access_key'), Kohana::config('amazon.account.secret_key'));
 }