public static function deleteFromServer($image) { if (JO_Registry::get('enable_amazon')) { $s3 = new JO_Api_Amazon(JO_Registry::get('awsAccessKey'), JO_Registry::get('awsSecretKey')); $s3->putBucket(JO_Registry::get('bucklet'), JO_Api_Amazon::ACL_PUBLIC_READ); if ($s3->getBucketLogging(JO_Registry::get('bucklet'))) { $s3->deleteObject(JO_Registry::get('bucklet'), $image); } } }
/** * Puts an object from a file (legacy function) * * @param string $file Input file path * @param string $bucket Bucket name * @param string $uri Object URI * @param constant $acl ACL constant * @param array $metaHeaders Array of x-amz-meta-* headers * @param string $contentType Content type * @return boolean */ public static function putObjectFile($file, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = null) { return self::putObject(JO_Api_Amazon::inputFile($file), $bucket, $uri, $acl, $metaHeaders, $contentType); }
/** * Get the S3 response * * @return object | false */ public function getResponse() { $query = ''; if (sizeof($this->parameters) > 0) { $query = substr($this->uri, -1) !== '?' ? '?' : '&'; foreach ($this->parameters as $var => $value) { if ($value == null || $value == '') { $query .= $var . '&'; } else { $query .= $var . '=' . $value . '&'; } } $query = substr($query, 0, -1); $this->uri .= $query; if (isset($this->parameters['acl']) || !isset($this->parameters['logging'])) { $this->resource .= $query; } } $url = (extension_loaded('openssl') ? 'https://' : 'http://') . $this->headers['Host'] . $this->uri; // var_dump($this->bucket, $this->uri, $this->resource, $url);exit; // Basic setup $curl = curl_init(); curl_setopt($curl, CURLOPT_USERAGENT, 'S3/php'); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_URL, $url); // Headers $headers = array(); $amz = array(); foreach ($this->amzHeaders as $header => $value) { if (strlen($value) > 0) { $headers[] = $header . ': ' . $value; } } foreach ($this->headers as $header => $value) { if (strlen($value) > 0) { $headers[] = $header . ': ' . $value; } } foreach ($this->amzHeaders as $header => $value) { if (strlen($value) > 0) { $amz[] = strToLower($header) . ':' . $value; } } $amz = sizeof($amz) > 0 ? "\n" . implode("\n", $amz) : ''; // Authorization string $headers[] = 'Authorization: ' . JO_Api_Amazon::__getSignature($this->verb . "\n" . $this->headers['Content-MD5'] . "\n" . $this->headers['Content-Type'] . "\n" . $this->headers['Date'] . $amz . "\n" . $this->resource); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, false); curl_setopt($curl, CURLOPT_WRITEFUNCTION, array(&$this, '__responseWriteCallback')); curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this, '__responseHeaderCallback')); // Request types switch ($this->verb) { case 'GET': break; case 'PUT': if ($this->fp !== false) { curl_setopt($curl, CURLOPT_PUT, true); curl_setopt($curl, CURLOPT_INFILE, $this->fp); if ($this->size > 0) { curl_setopt($curl, CURLOPT_INFILESIZE, $this->size); } } elseif ($this->data !== false) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($curl, CURLOPT_POSTFIELDS, $this->data); if ($this->size > 0) { curl_setopt($curl, CURLOPT_BUFFERSIZE, $this->size); } } else { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); } 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; } // Execute, grab errors if (curl_exec($curl)) { $this->response->code = curl_getinfo($curl, CURLINFO_HTTP_CODE); } else { $this->response->error = array('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->headers['type']) && $this->response->headers['type'] == 'application/xml' && isset($this->response->body)) { $this->response->body = simplexml_load_string($this->response->body); // Grab JO_Api_Amazon errors if (!in_array($this->response->code, array(200, 204)) && isset($this->response->body->Code, $this->response->body->Message)) { $this->response->error = array('code' => (string) $this->response->body->Code, 'message' => (string) $this->response->body->Message); if (isset($this->response->body->Resource)) { $this->response->error['resource'] = (string) $this->response->body->Resource; } unset($this->response->body); } } // Clean up file resources if ($this->fp !== false && is_resource($this->fp)) { fclose($this->fp); } return $this->response; }
public static function uploadEventImage1($avatar, $user_id = 0) { try { $added_date = time(); if (is_array($user_info = Model_Users::getUser($user_id))) { $added_date = $user_info['date_added']; } $date_added = WM_Date::format($added_date, 'yy-mm-dd H:i:s'); $s3 = new JO_Api_Amazon(JO_Registry::get('awsAccessKey'), JO_Registry::get('awsSecretKey')); $s3->putBucket(JO_Registry::get('bucklet'), JO_Api_Amazon::ACL_PUBLIC_READ); if ($s3->getBucketLogging(JO_Registry::get('bucklet'))) { if (($imageinfo = @getimagesize($avatar)) !== false) { $ext = strtolower(strrchr($avatar, ".")); $name = $user_id . $ext; $image_path = 'events/' . WM_Date::format($date_added, 'yy/mm/'); if (!file_exists(BASE_PATH . '/uploads/cache_events/' . $image_path) || !is_dir(BASE_PATH . '/uploads/cache_events/' . $image_path)) { @mkdir(BASE_PATH . '/uploads/cache_events/' . $image_path, 0777, true); } @copy($avatar, BASE_PATH . '/uploads/cache_events/' . $image_path . $name); if (self::uploatToServer(BASE_PATH . '/uploads/cache_events/' . $image_path . $name, $image_path . $name)) { $model_images = new Helper_Images(); $temp_width = 0; $temp_height = 0; $sizes = self::userThumbSizes(); if ($sizes) { foreach ($sizes as $size => $prefix) { $sizes = explode('x', $size); $width = (int) isset($sizes[0]) ? $sizes[0] : 0; $height = (int) isset($sizes[1]) ? $sizes[1] : 0; $name_pref = basename($name, $ext) . $prefix . $ext; if ($width && $height) { $thumb_a = $model_images->resize('/cache_events/' . $image_path . $name, $width, $height, true); } else { if ($width && !$height) { $thumb_a = $model_images->resizeWidth('/cache_events/' . $image_path . $name, $width); } else { if ($height && !$width) { $thumb_a = $model_images->resizeHeight('/cache_events/' . $image_path . $name, $height); } } } if ($prefix == '_B') { $temp_width = $model_images->getSizes('width'); $temp_height = $model_images->getSizes('height'); } $thumb_a1 = explode('/uploads/', $thumb_a); if ($thumb_a1 && isset($thumb_a1[1])) { if (!self::uploatToServer(BASE_PATH . '/uploads/' . $thumb_a1[1], $image_path . $name_pref)) { } } } } //$model_images->deleteImages('/cache_events/' . $image_path . $name); if ($temp_width) { return array('store' => 'amazons3', 'image' => $image_path . $name, 'width' => $temp_width, 'height' => $temp_height); } else { return false; } } else { return false; } } else { return false; } } } catch (JO_Exception $e) { return false; } return false; }
public function indexAction() { if (!WM_Users::allow('edit', 'modules')) { JO_Session::set('error_permision', $this->translate('You do not have permission to this action')); $this->redirect($this->getRequest()->getBaseUrl() . $this->getRequest()->getModule() . '/modules_storage/'); } $request = $this->getRequest(); if (JO_Session::get('successfu_edite')) { $this->view->successfu_edite = true; JO_Session::clear('successfu_edite'); } if ($request->isPost()) { //validate app id $this->view->error = false; try { $s3 = new JO_Api_Amazon($request->getPost('amazons3[amazons3_access_key]'), $request->getPost('amazons3[amazons3_secret_key]')); //$s3->putBucket($request->getPost('amazons3[amazons3_bucklet]'), JO_Api_Amazon::ACL_PUBLIC_READ); $loged = $s3->getBucketLogging($request->getPost('amazons3[amazons3_bucklet]')); if ($loged) { $upload = $s3->putObjectString('test', $request->getPost('amazons3[amazons3_bucklet]'), 'test_upload.txt', JO_Api_Amazon::ACL_PUBLIC_READ); if (!$upload) { $this->view->error = sprintf($this->translate('Unable to upload to Bucklet "%s"'), $request->getPost('amazons3[amazons3_bucklet]')); $loged = false; } else { $is_file = @file_get_contents(trim($request->getPost('amazons3[amazons3_bucklet_location]'), '/') . '/test_upload.txt'); if ($is_file != 'test') { $this->view->error = sprintf($this->translate('Unable to read test file "%s"'), trim($request->getPost('amazons3[amazons3_bucklet_location]'), '/') . '/test_upload.txt'); $loged = false; } } } else { $this->view->error = sprintf($this->translate('Bucklet "%s" not found'), $request->getPost('amazons3[amazons3_bucklet]')); $loged = false; } } catch (JO_Exception $e) { $this->view->error = $e->getMessage(); $loged = false; } if ($loged) { Model_Settings::updateAll(array('amazons3' => $request->getPost('amazons3'))); JO_Session::set('successfu_edite', true); $this->redirect($this->getRequest()->getBaseUrl() . $this->getRequest()->getModule() . '/modules_storage_amazons3/'); } else { if (!$this->view->error) { $this->view->error = $this->translate('Invalid App configuration'); } } } $this->view->modules_url = $this->getRequest()->getModule() . '/modules'; $this->view->modules_storage_url = $this->getRequest()->getModule() . '/modules_storage'; $store_config = Model_Settings::getSettingsPairs(array('filter_group' => 'amazons3')); if (!isset($store_config['amazons3_access_key'])) { $store_config['amazons3_access_key'] = ''; } if (!isset($store_config['amazons3_secret_key'])) { $store_config['amazons3_secret_key'] = ''; } if (!isset($store_config['amazons3_bucklet'])) { $store_config['amazons3_bucklet'] = ''; } if (!isset($store_config['amazons3_bucklet_location'])) { $store_config['amazons3_bucklet_location'] = ''; } foreach ($store_config as $key => $data) { if ($request->issetPost('amazons3[' . $key . ']')) { $this->view->{$key} = $request->getPost('amazons3[' . $key . ']'); } else { $this->view->{$key} = $data; } } }