Copy an object
public static copyObject ( string $srcBucket, string $srcUri, string $bucket, string $uri, constant $acl = self::ACL_PRIVATE, array $metaHeaders = [], array $requestHeaders = [], constant $storageClass = self::STORAGE_CLASS_STANDARD ) : mixed | false | ||
$srcBucket | string | Source bucket name |
$srcUri | string | Source object URI |
$bucket | string | Destination bucket name |
$uri | string | Destination object URI |
$acl | constant | ACL constant |
$metaHeaders | array | Optional array of x-amz-meta-* headers |
$requestHeaders | array | Optional array of request headers (content type, disposition, etc.) |
$storageClass | constant | Storage class constant |
return | mixed | false | | false |
/** * Copy a transform for a file from source location to target location. * * @param AssetFileModel $file * @param $source * @param $target * @return mixed */ public function copyTransform(AssetFileModel $file, $source, $target) { $this->_prepareForRequests(); $basePath = $this->_getPathPrefix() . $file->getFolder()->fullPath; $bucket = $this->getSettings()->bucket; @$this->_s3->copyObject($bucket, $basePath . $source . '/' . $file->filename, $bucket, $basePath . $target . '/' . $file->filename, \S3::ACL_PUBLIC_READ); }
/** * @inheritDoc BaseAssetSourceType::copySourceFile() * * @param $sourceUri * @param $targetUri * * @return bool */ protected function copySourceFile($sourceUri, $targetUri) { if ($sourceUri == $targetUri) { return true; } $bucket = $this->getSettings()->bucket; return (bool) @$this->_s3->copyObject($bucket, $sourceUri, $bucket, $targetUri, $this->_getACL()); }
public function execute() { $this->AWS_ACCESS_KEY = 'YOUR_AWS_ACCESS_KEY'; $this->AWS_SECRET_KEY = 'YOUR_AWS_SECRET_KEY'; $this->AWS_S3_BUCKET = 'YOUR_AWS_S3_BUCKET'; $this->AWS_S3_PUBLIC = true; $this->AWS_S3_SSL = false; $s3 = new S3(); $s3->setAuth($this->AWS_ACCESS_KEY, $this->AWS_SECRET_KEY); $s3->useSSL = $this->AWS_S3_SSL; // In my situation the images were in two different S3 buckets already. It will search these locations to try and find it. // Your images are probably local already, so you may need to modify the code further down to work with local directories. //$s3Buckets = array(...); $dbw = wfGetDB(DB_MASTER); $counter = 0; $iIncrement = 10000; for ($i = 0;; $i += $iIncrement) { $res = $dbw->select(array('image', 'imagelinks', 'page'), array('image.img_name', 'image.img_path', 'page.page_title'), 'image.img_name = imagelinks.il_to and imagelinks.il_from = page.page_id and page.page_namespace = 0 limit ' . $i . ', ' . $iIncrement, array()); if (!$res) { echo 'No for rows.\\n'; exit; } $logoPath = ''; foreach ($res as $row) { echo "counter:{$counter}\n"; echo "i:{$i}\n"; ++$counter; if (!$row->img_name || !$row->img_path) { continue; } echo 'img_name:' . $row->img_name . "\n"; echo 'img_path:' . $row->img_path . "\n"; echo 'page_title:' . $row->page_title . "\n"; $file = wfFindFile($row->img_name, array()); if ($file) { $path = $file->getFullUrl(); $path = str_replace('http://s3.amazonaws.com/' . $this->AWS_S3_BUCKET . '/', '', $path); echo "path:{$path}\n"; // If you have images that are already stored locally, you will need to modify this section. Instead of an S3::copyObject you // may need to use the S3::putObject method to upload your local copy. foreach ($s3Buckets as $s3Bucket) { if ($s3->copyObject($s3Bucket, $row->img_path, $this->AWS_S3_BUCKET, $path, $this->AWS_S3_PUBLIC ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE)) { echo 'SUCCESS:' . $row->img_name . "\n"; break; } else { echo 'ERROR1:' . $row->img_name . "\n"; } } } else { echo 'ERROR2:' . $row->img_name . "\n"; } echo "\n"; } } }
/** * copy to s3 on the file on s3 * @param string $sourceLocationOnS3 - path of source file to be copied in the S3 server * @param string $copyLocationOnS3 - path to copy * @param string $source_bucket - if the bucket of the source is different from the current S3 bucket * @param string $copy_bucket - if the bucket of to copy is different from the current S3 bucket * @param string $permission - the access permissions the file should have, defaults to Public Read Acess * @param string $mimeType - set the mime type of the object in S3, defaults to autodetect * @return mixed - returns an array with details of the uploaded file on S3 for success, FALSE on failure */ public function copyObject($sourceLocationOnS3, $copyLocationOnS3, $sourceBucket = false, $copyBucket = false, $permission = self::ACL_PUBLIC_READ, $mimeType = array()) { try { if ($sourceBucket == false || $sourceBucket == null) { $sourceBucket = $this->bucket; } if ($copyBucket == false || $copyBucket == null) { $copyBucket = $this->bucket; } S3::copyObject($sourceBucket, $sourceLocationOnS3, $copyBucket, $copyLocationOnS3, $permission, array(), $mimeType); $info = S3::getObjectInfo($copyBucket, $copyLocationOnS3); return array('name' => basename($copyLocationOnS3), 'url' => $this->buildUrlToFile($copyLocationOnS3), 'size' => $info['size']); } catch (Exception $e) { return false; } }
$type = $_POST['type']; } if (isset($_POST) && isset($_POST['extension'])) { $file_extension = $_POST['extension']; } $bucket_name = $aws['bucket']; $s3 = new S3($aws['key'], $aws['secret']); $results = array('success' => false, 'url' => 'http://blockstrap.com', 'msg' => 'Unable to copy or delete file'); $year = date('y'); $month = date('m'); $day = date('d'); $original_location = 'temp/' . $year . '/' . $month . '/' . $hash . '.' . $file_extension; $new_location = 'paid/' . $year . '/' . $month . '/' . $day . '/' . $txid . '.' . $file_extension; $vars = '?txid=' . $txid . '&extension=' . $file_extension . '&type=' . $type . '&chain=' . $chain; if ($save === true || $save === 'true') { if ($s3->copyObject($bucket_name, $original_location, $bucket_name, $new_location)) { if ($s3->deleteObject($bucket_name, $original_location)) { $results['success'] = true; $results['url'] = $urls['image'] . $vars; $results['msg'] = 'Copied and deleted file'; } else { $results['msg'] = 'Unable to delete original file'; } } } else { if ($s3->deleteObject($bucket_name, $original_location)) { $results['success'] = true; $results['url'] = false; $results['msg'] = 'Deleted file'; } else { $results['msg'] = 'Unable to delete file';
function uploadProfilePhoto($name, $path) { if ($name) { $oldname = strtolower($name); $ext = substr(strrchr($oldname, "."), 1); if ($ext != 'gif' && $ext != 'jpg' && $ext != 'jpeg' && $ext != 'png' && $ext != 'bmp') { return "ext"; } else { $targetpath = $path . $name; $newname = $name; //md5(time().$count).".".$ext; if (defined('USE_S3') && USE_S3) { // s3 bucket start $s3 = new S3(awsAccessKey, awsSecretKey); $s3->putBucket(BUCKET_NAME, S3::ACL_PRIVATE); $folder_orig_Name = 'files/photos/' . trim($newname); //$s3->putObjectFile($targetpath,BUCKET_NAME ,$folder_orig_Name ,S3::ACL_PRIVATE); $s3->copyObject(BUCKET_NAME, DIR_USER_PHOTOS_THUMB . trim($newname), BUCKET_NAME, $folder_orig_Name, S3::ACL_PRIVATE); //s3 bucket end //unlink($targetpath); } return $newname; } } else { return false; } }
public function action_update() { //template header $this->template->title = __('Edit Product'); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit Product'))); $this->template->styles = array('css/sortable.css' => 'screen', '//cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/css/jquery.fileupload.css' => 'screen', 'css/jasny-bootstrap.min.css' => 'screen'); $this->template->scripts['footer'] = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js', 'js/jasny-bootstrap.min.js', 'js/oc-panel/products.js', 'js/jquery-sortable-min.js', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/js/vendor/jquery.ui.widget.js', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/js/jquery.iframe-transport.js', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/js/jquery.fileupload.js'); $cats = Model_Category::get_as_array(); $order = Model_Category::get_multidimensional(); $obj_product = new Model_Product($this->request->param('id')); if ($obj_product->loaded()) { // get currencies from product, returns array $currency = $obj_product::get_currency(); $this->template->content = View::factory('oc-panel/pages/products/update', array('product' => $obj_product, 'categories' => $cats, 'order_categories' => $order, 'currency' => $currency)); if ($product = $this->request->post()) { // save product file if (isset($_FILES['file_name'])) { if ($file = $_FILES['file_name']) { $file = $obj_product->save_product($file); if ($file != FALSE) { $obj_product->file_name = $file; } else { Alert::set(Alert::INFO, __('Product is not uploaded.')); } } } // deleting single image by path $deleted_image = core::post('img_delete'); if (is_numeric($deleted_image)) { $img_path = $obj_product->gen_img_path($obj_product->id_product, $obj_product->created); $img_seoname = $obj_product->seotitle; // delete image from Amazon S3 if (core::config('image.aws_s3_active')) { require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php'); $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key')); //delete original image $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . $deleted_image . '.jpg'); //delete formated image $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . $deleted_image . '.jpg'); //re-ordering image file names for ($i = $deleted_image; $i < $obj_product->has_images; $i++) { //rename original image $s3->copyObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . ($i + 1) . '.jpg', core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . $i . '.jpg', S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . ($i + 1) . '.jpg'); //rename formated image $s3->copyObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg', core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . $i . '.jpg', S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg'); } } if (!is_dir($img_path)) { return FALSE; } else { //delete original image @unlink($img_path . $img_seoname . '_' . $deleted_image . '.jpg'); //delete formated image @unlink($img_path . 'thumb_' . $img_seoname . '_' . $deleted_image . '.jpg'); //re-ordering image file names for ($i = $deleted_image; $i < $obj_product->has_images; $i++) { rename($img_path . $img_seoname . '_' . ($i + 1) . '.jpg', $img_path . $img_seoname . '_' . $i . '.jpg'); rename($img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg', $img_path . 'thumb_' . $img_seoname . '_' . $i . '.jpg'); } } $obj_product->has_images = $obj_product->has_images > 0 ? $obj_product->has_images - 1 : 0; $obj_product->updated = Date::unix2mysql(); try { $obj_product->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } $this->redirect(Route::url('oc-panel', array('controller' => 'product', 'action' => 'update', 'id' => $obj_product->id_product))); } // end of img delete //delete product file $product_delete = core::post('product_delete'); if ($product_delete) { $p_path = $obj_product->get_file($obj_product->file_name); if (!is_file($p_path)) { return FALSE; } else { @chmod($p_path, 0755); //delete product unlink($p_path); $obj_product->file_name = ''; $obj_product->save(); $this->redirect(Route::url('oc-panel', array('controller' => 'product', 'action' => 'update', 'id' => $obj_product->id_product))); } } $product['status'] = (!isset($_POST['status']) or core::post('status') === NULL) ? Model_Product::STATUS_NOACTIVE : Model_Product::STATUS_ACTIVE; $product['updated'] = Date::unix2mysql(); //we do this so we assure use the entire day , nasty $product['offer_valid'] .= ' 23:59:59'; $product['featured'] .= ' 23:59:59'; // each field in edit product foreach ($product as $field => $value) { // do not include submit if ($field != 'submit' and $field != 'notify') { // check if its different, and set it is if ($value != $obj_product->{$field}) { $obj_product->{$field} = $value; // if title is changed, make new seotitle if ($field == 'title') { $seotitle = $obj_product->gen_seotitle($product['title']); $obj_product->seotitle = $seotitle; } } } } // save product or trow exeption try { $obj_product->save(); Alert::set(Alert::SUCCESS, __('Product saved.')); Sitemap::generate(); //notify users of new update if ($this->request->post('notify')) { //get users with that product $query = DB::select('email')->select('name')->from(array('users', 'u'))->join(array('orders', 'o'), 'INNER')->on('u.id_user', '=', 'o.id_user')->where('u.status', '=', Model_User::STATUS_ACTIVE)->where('o.status', '=', Model_Order::STATUS_PAID)->where('o.id_product', '=', $obj_product->id_product)->execute(); $users = $query->as_array(); if (count($users) > 0) { //download link $download = ''; if ($obj_product->has_file() == TRUE) { $download = '\\n\\n==== ' . __('Download') . ' ====\\n' . Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')); } //theres an expire? 0 = unlimited $expire = ''; $expire_hours = Core::config('product.download_hours'); $expire_times = Core::config('product.download_times'); if (($expire_hours > 0 or $expire_times > 0) and $obj_product->has_file() == TRUE) { if ($expire_hours > 0 and $expire_times > 0) { $expire = sprintf(__('Your download expires in %u hours and can be downloaded %u times.'), $expire_hours, $expire_times); } elseif ($expire_hours > 0) { $expire = sprintf(__('Your download expires in %u hours.'), $expire_hours); } elseif ($expire_times > 0) { $expire = sprintf(__('Can be downloaded %u times.'), $expire_times); } $expire = '\\n' . $expire; } if (!Email::content($users, '', NULL, NULL, 'product-update', array('[TITLE]' => $obj_product->title, '[URL.PRODUCT]' => Route::url('product', array('seotitle' => $obj_product->seotitle, 'category' => $obj_product->category->seoname)), '[DOWNLOAD]' => $download, '[EXPIRE]' => $expire, '[VERSION]' => $obj_product->version))) { Alert::set(Alert::ERROR, __('Error on mail delivery, not sent')); } else { Alert::set(Alert::SUCCESS, __('Email sent to all the users')); } } else { Alert::set(Alert::ERROR, __('Mail not sent')); } } } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } // save images if (isset($_FILES)) { foreach ($_FILES as $file_name => $file) { if ($file_name != 'file_name') { $file = $obj_product->save_image($file); } if ($file) { $obj_product->has_images++; } } //since theres images save the ad again... try { $obj_product->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } } } }
function copy_file_to_S3($origin_file, $destiny_file, $view_proccess = false) { $s3 = new S3(AWS_ACCES_KEY, AWS_SECRET_KEY); $success = $s3->copyObject("owlgroup", $origin_file, "owlgroup", $destiny_file, S3::ACL_PUBLIC_READ); if ($success) { if ($view_proccess) { W("{$origin_file} ✓ <br>"); ob_flush(); flush(); ob_end_flush(); } } else { if ($view_proccess) { W("{$origin_file} ERROR <br>"); } } return $success; }
/** * [delete_image description] * @param integer $deleted_image * @return void */ public function delete_image($deleted_image) { $img_path = $this->image_path(); $img_seoname = $this->seotitle; // delete image from Amazon S3 if (core::config('image.aws_s3_active')) { require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php'); $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key')); //delete original image $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . $deleted_image . '.jpg'); //delete formated image $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . $deleted_image . '.jpg'); //re-ordering image file names for ($i = $deleted_image; $i < $this->has_images; $i++) { //rename original image $s3->copyObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . ($i + 1) . '.jpg', core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . $i . '.jpg', S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . ($i + 1) . '.jpg'); //rename formated image $s3->copyObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg', core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . $i . '.jpg', S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg'); } } //delte image from local filesystem if (!is_dir($img_path)) { return FALSE; } else { //delete original image @unlink($img_path . $img_seoname . '_' . $deleted_image . '.jpg'); //delete formated image @unlink($img_path . 'thumb_' . $img_seoname . '_' . $deleted_image . '.jpg'); //re-ordering image file names for ($i = $deleted_image; $i < $this->has_images; $i++) { @rename($img_path . $img_seoname . '_' . ($i + 1) . '.jpg', $img_path . $img_seoname . '_' . $i . '.jpg'); @rename($img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg', $img_path . 'thumb_' . $img_seoname . '_' . $i . '.jpg'); } } $this->has_images = $this->has_images > 0 ? $this->has_images - 1 : 0; $this->last_modified = Date::unix2mysql(); try { $this->save(); return TRUE; } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } return FALSE; }
private function _createS3File() { //format the name and stuff $filename = basename($this->args('key')); $filename = str_replace(" ", "_", $filename); $filename = preg_replace("/[^-_.+[0-9a-zA-Z]/", "", $filename); $path = "assets/" . S3File::getNiceDir($filename); //check our info out. $info = $this->_lookupFileInfo(); //create new s3 file $file = new S3File(); $file->set('user_id', User::$me->id); $file->set('type', $info['type']); $file->set('size', $info['size']); $file->set('hash', $info['hash']); $file->set('add_date', date('Y-m-d H:i:s')); $file->set('bucket', AMAZON_S3_BUCKET_NAME); $file->set('path', $path); $file->save(); //copy to new location in s3. $s3 = new S3(AMAZON_AWS_KEY, AMAZON_AWS_SECRET); $s3->copyObject($this->args('bucket'), $this->args('key'), AMAZON_S3_BUCKET_NAME, $path, S3::ACL_PUBLIC_READ); //remove the uploaded file. $s3->deleteObject($this->args('bucket'), $this->args('key')); return $file; }
static function move_item($old_item, $new_item) { self::get_s3(); S3::copyObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("fs/" . $old_item->relative_path()), module::get_var("aws_s3", "bucket_name"), self::get_resource_url("fs/" . $new_item->relative_path()), $new_item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE); S3::deleteObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("fs/" . $old_item->relative_path())); S3::copyObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("rs/" . $old_item->relative_path()), module::get_var("aws_s3", "bucket_name"), self::get_resource_url("rs/" . $new_item->relative_path()), $new_item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE); S3::deleteObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("rs/" . $old_item->relative_path())); S3::copyObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("th/" . $old_item->relative_path()), module::get_var("aws_s3", "bucket_name"), self::get_resource_url("th/" . $new_item->relative_path()), $new_item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE); S3::deleteObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("th/" . $old_item->relative_path())); }
public function copyObject($srcBucket, $srcUri, $bucket, $uri) { return S3::copyObject($srcBucket, $srcUri, $bucket, $uri); }
$s3 = new S3($GLOBALS['AWSkey'], $GLOBALS['AWSsecret']); $doneagroups = array(); while ($row = mysql_fetch_row($result)) { //set path to aid/asid/ or aid/agroupid/ - won't interefere with random values, and easier to do. if ($row[1] == 0) { $path = $row[5] . '/' . $row[0]; $curs3asid = $row[0]; } else { $path = $row[5] . '/' . $row[1]; $curs3asid = $row[1]; } if ($row[1] == 0 || !in_array($row[1], $doneagroups)) { preg_match_all('/@FILE:(.*?)@/', $row[2] . $row[3] . $row[4], $matches); $tomove = array_unique($matches[1]); foreach ($tomove as $file) { if (@$s3->copyObject($GLOBALS['AWSbucket'], "adata/{$curs3asid}/{$file}", $GLOBALS['AWSbucket'], "adata/{$path}/{$file}")) { @$s3->deleteObject($GLOBALS['AWSbucket'], "adata/{$curs3asid}/{$file}"); } } if ($row[1] > 0) { $doneagroups[] = $row[1]; } } $la = addslashes(preg_replace('/@FILE:/', "@FILE:{$path}/", $row[2])); $bla = addslashes(preg_replace('/@FILE:/', "@FILE:{$path}/", $row[3])); $rla = addslashes(preg_replace('/@FILE:/', "@FILE:{$path}/", $row[4])); $query = "UPDATE imas_assessment_sessions SET lastanswers='{$la}',bestlastanswers='{$bla}',reviewlastanswers='{$rla}' WHERE id={$row[0]}"; $res = mysql_query($query) or die("Query failed : {$query}:" . mysql_error()); } echo 'Done up through s3 file change. <a href="upgrade.php?last=30.5">Continue</a>'; exit;
public function action_do_edit($modpack_id) { if (empty($modpack_id)) { return Redirect::to('dashboard'); } $modpack = Modpack::find($modpack_id); if (empty($modpack_id)) { return Redirect::to('dashboard'); } $rules = array('name' => 'required|unique:modpacks,name,' . $modpack->id, 'slug' => 'required|unique:modpacks,slug,' . $modpack->id); $messages = array('name_required' => 'You must enter a modpack name.', 'slug_required' => 'You must enter a modpack slug'); $validation = Validator::make(Input::all(), $rules, $messages); if ($validation->fails()) { return Redirect::back()->with_errors($validation->errors); } $url = Config::get('solder.repo_location') . Input::get('slug') . '/resources/'; $modpack->name = Input::get('name'); $oldSlug = $modpack->slug; $modpack->slug = Input::get('slug'); $modpack->icon_md5 = UrlUtils::get_remote_md5($url . 'icon.png'); $modpack->logo_md5 = UrlUtils::get_remote_md5($url . 'logo_180.png'); $modpack->background_md5 = UrlUtils::get_remote_md5($url . 'background.jpg'); $modpack->hidden = Input::get('hidden') ? true : false; $modpack->private = Input::get('private') ? true : false; $modpack->save(); $useS3 = Config::get('solder.use_s3'); if ($useS3) { $resourcePath = path('storage') . 'resources/' . $modpack->slug; } else { $resourcePath = path('public') . 'resources/' . $modpack->slug; } /* Create new resources directory for modpack */ if (!file_exists($resourcePath)) { mkdir($resourcePath); } /* If slug changed, move resources and delete old slug directory */ if ($oldSlug != $modpack->slug) { $oldPath = path('public') . 'resources/' . $oldSlug; if (Config::get('solder.use_s3')) { try { S3::copyObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/logo.png', Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/logo.png', S3::ACL_PUBLIC_READ); S3::copyObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/background.png', Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/background.png', S3::ACL_PUBLIC_READ); S3::copyObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/icon.png', Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/icon.png', S3::ACL_PUBLIC_READ); S3::deleteObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/logo.png'); S3::deleteObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/background.png'); S3::deleteObject(Config::get('solder.bucket'), 'resources/' . $oldSlug . '/icon.png'); } catch (Exception $e) { } $oldPath = path('storage') . 'resources/' . $oldSlug; } if (file_exists($oldPath . "/logo.png")) { copy($oldPath . "/logo.png", $resourcePath . "/logo.png"); unlink($oldPath . "/logo.png"); } if (file_exists($oldPath . "/background.png")) { copy($oldPath . "/background.png", $resourcePath . "/background.png"); unlink($oldPath . "/background.png"); } if (file_exists($oldPath . "/icon.png")) { copy($oldPath . "/icon.png", $resourcePath . "/icon.png"); unlink($oldPath . "/icon.png"); } rmdir($oldPath); } /* Image dohickery */ $logo = Input::file('logo'); if (!empty($logo['name'])) { $success = Resizer::open(Input::file('logo'))->resize(180, 110, 'exact')->save($resourcePath . "/logo.png", 90); if ($useS3) { S3::putObject(S3::inputFile($resourcePath . '/logo.png', false), Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/logo.png', S3::ACL_PUBLIC_READ); } if ($success) { $modpack->logo = true; $modpack->logo_md5 = md5_file($resourcePath . "/logo.png"); } } $background = Input::file('background'); if (!empty($background['name'])) { $success = Resizer::open(Input::file('background'))->resize(880, 520, 'exact')->save($resourcePath . "/background.png", 90); if ($useS3) { S3::putObject(S3::inputFile($resourcePath . '/background.png', false), Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/background.png', S3::ACL_PUBLIC_READ); } if ($success) { $modpack->background = true; $modpack->background_md5 = md5_file($resourcePath . "/background.png"); } } $icon = Input::file('icon'); if (!empty($icon['name'])) { $success = Resizer::open(Input::file('icon'))->resize(50, 50, 'exact')->save($resourcePath . "/icon.png", 90); if ($useS3) { S3::putObject(S3::inputFile($resourcePath . '/icon.png', false), Config::get('solder.bucket'), 'resources/' . $modpack->slug . '/icon.png', S3::ACL_PUBLIC_READ); } if ($success) { $modpack->icon = true; $modpack->icon_md5 = md5_file($resourcePath . "/icon.png"); } } $modpack->save(); Cache::forget('modpack.' . $modpack->slug); Cache::forget('modpacks'); /* Client Syncing */ $clients = Input::get('clients'); $modpack->clients()->sync($clients); return Redirect::to('modpack/view/' . $modpack->id)->with('success', 'Modpack edited'); }
function rename_video_s3() { $s3 = new S3('AKIAIDUB5W5AJBZQCWOQ', 'cXEQHaDhVGkXqKp+bw5HZnJnsga0AMo8vY8p4/+n'); $s3->copyObject('dharmaelearning', $_POST['name'], 'dharmaelearning', $_POST['newname'], S3::ACL_PUBLIC_READ, array(), array(), S3::STORAGE_CLASS_STANDARD); $s3->deleteObject('dharmaelearning', $_POST['name']); echo 1; exit; }
public static function duplicateFile($storageFileID, $newName, $zip, $contentType = null) { self::requireLibrary(); if (!$newName) { throw new Exception("New name not provided"); } $localInfo = self::getFileInfoByID($storageFileID); if (!$localInfo) { throw new Exception("File {$storageFileID} not found"); } S3::setAuth(Z_CONFIG::$S3_ACCESS_KEY, Z_CONFIG::$S3_SECRET_KEY); $success = S3::copyObject(Z_CONFIG::$S3_BUCKET, self::getPathPrefix($localInfo['hash'], $localInfo['zip']) . $localInfo['filename'], Z_CONFIG::$S3_BUCKET, self::getPathPrefix($localInfo['hash'], $zip) . $newName, S3::ACL_PRIVATE, array(), $contentType ? array("Content-Type" => $contentType) : array()); if (!$success) { return false; } $info = new Zotero_StorageFileInfo(); foreach ($localInfo as $key => $val) { $info->{$key} = $val; } $info->filename = $newName; return self::addFile($info); }
/** * rename location icon * @param string $new_name * @return boolean */ public function rename_icon($new_name) { if (!$this->_loaded) { throw new Kohana_Exception('Cannot delete :model model because it is not loaded.', array(':model' => $this->_object_name)); } @rename('images/locations/' . $this->seoname . '.png', 'images/locations/' . $new_name . '.png'); if (core::config('image.aws_s3_active')) { require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php'); $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key')); $s3->copyObject(core::config('image.aws_s3_bucket'), 'images/locations/' . $this->seoname . '.png', core::config('image.aws_s3_bucket'), 'images/locations/' . $new_name . '.png', S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), 'images/locations/' . $this->seoname . '.png'); } }
function uploadAndInsertFile($files, $caseid, $cmnt, $projId, $domain = HTTP_ROOT) { $CaseFile = ClassRegistry::init('CaseFile'); $CaseFile->recursive = -1; $CaseFile->cacheQueries = false; $sql = "SELECT SUM(file_size) AS file_size FROM case_files WHERE company_id = '" . SES_COMP . "'"; $res1 = $CaseFile->query($sql); $fkb = $res1['0']['0']['file_size']; $allfiles = ""; $filename = ""; $sizeinkb = 0; $fileid = 0; $filecount = 0; foreach ($files as $file) { if ($file && strstr($file, "|")) { $fl = explode("|", $file); if (isset($fl['0'])) { $filename = $fl['0']; } if (isset($fl['1'])) { $sizeinkb = $fl['1']; } if (isset($fl['2'])) { $fileid = $fl['2']; } if (isset($fl['3'])) { $filecount = $fl['3']; } if ($filecount && $fileid) { ###### Update case file table for same file $csFile['id'] = $fileid; $csFile['count'] = $filecount; $CaseFile->saveAll($csFile); } elseif ($fileid) { continue; } $res['file_error'] = 0; if (strtolower($GLOBALS['Userlimitation']['storage']) == 'unlimited' || $fkb / 1024 < $GLOBALS['Userlimitation']['storage']) { $fkb += $sizeinkb; ###### Insert to case file table $csFiles['user_id'] = SES_ID; $csFiles['project_id'] = $projId; $csFiles['company_id'] = SES_COMP; $csFiles['easycase_id'] = $caseid; $csFiles['file'] = $filename; $csFiles['file_size'] = $sizeinkb; $csFiles['comment_id'] = $cmnt; if ($CaseFile->saveAll($csFiles)) { if (USE_S3) { $s3 = new S3(awsAccessKey, awsSecretKey); $ret_res = $s3->copyObject(BUCKET_NAME, DIR_CASE_FILES_S3_FOLDER_TEMP . $filename, BUCKET_NAME, DIR_CASE_FILES_S3_FOLDER . $filename, S3::ACL_PRIVATE); if ($ret_res) { //$s3->deleteObject(BUCKET_NAME, DIR_CASE_FILES_S3_FOLDER_TEMP.$filename, S3::ACL_PRIVATE); } } } $allfiles .= "<a href='" . $domain . "users/login/?file=" . $filename . "' target='_blank' style='text-decoration:underline;color:#0571B5;line-height:24px;'>" . $filename . "</a> <font style='color:#989898;font-size:12px;'>(" . number_format($sizeinkb, 1) . " kb)</font><br/>"; } else { $res['file_error'] = 1; $res['efile'][] = $file; } } } $res['allfiles'] = $allfiles; $filesize = $fkb / 1024; $res['storage'] = number_format($filesize, 2); return $res; }
/** * Set primary image by swapping ids * @param integer $primary_image * @return void */ public function set_primary_image($primary_image) { // if ad doesn't have at least two images do nothing if ($this->has_images < 2) { return; } $img_path = $this->image_path(); // delete image from Amazon S3 if (core::config('image.aws_s3_active')) { require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php'); $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key')); //re-ordering image file names $s3->copyObject(core::config('image.aws_s3_bucket'), $this->image_name('1'), core::config('image.aws_s3_bucket'), $this->image_name('1_old'), S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), $this->image_name('1')); $s3->copyObject(core::config('image.aws_s3_bucket'), $this->image_name('1', 'thumb'), core::config('image.aws_s3_bucket'), $this->image_name('1_old', 'thumb'), S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), $this->image_name('1', 'thumb')); $s3->copyObject(core::config('image.aws_s3_bucket'), $this->image_name($primary_image), core::config('image.aws_s3_bucket'), $this->image_name('1'), S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), $this->image_name($primary_image)); $s3->copyObject(core::config('image.aws_s3_bucket'), $this->image_name($primary_image, 'thumb'), core::config('image.aws_s3_bucket'), $this->image_name('1', 'thumb'), S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), $this->image_name($primary_image, 'thumb')); $s3->copyObject(core::config('image.aws_s3_bucket'), $this->image_name('1_old'), core::config('image.aws_s3_bucket'), $this->image_name($primary_image), S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), $this->image_name('1_old')); $s3->copyObject(core::config('image.aws_s3_bucket'), $this->image_name('1_old', 'thumb'), core::config('image.aws_s3_bucket'), $this->image_name($primary_image, 'thumb'), S3::ACL_PUBLIC_READ); $s3->deleteObject(core::config('image.aws_s3_bucket'), $this->image_name('1_old', 'thumb')); } //re-ordering image file names @rename($this->image_name('1'), $this->image_name('1_old')); @rename($this->image_name('1', 'thumb'), $this->image_name('1_old', 'thumb')); @rename($this->image_name($primary_image), $this->image_name('1')); @rename($this->image_name($primary_image, 'thumb'), $this->image_name('1', 'thumb')); @rename($this->image_name('1_old'), $this->image_name($primary_image)); @rename($this->image_name('1_old', 'thumb'), $this->image_name($primary_image, 'thumb')); $this->last_modified = Date::unix2mysql(); try { $this->save(); return TRUE; } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } return FALSE; }
public function copyToBucket($bucket) { //load up S3 for download $s3 = new S3(AMAZON_AWS_KEY, AMAZON_AWS_SECRET); $result = $s3->copyObject($this->get('bucket'), $this->get('path'), $bucket, $this->get('path'), S3::ACL_PUBLIC_READ); $this->set('bucket', $bucket); $this->save(); return $result; }
/** * @inheritDoc BaseAssetSourceType::copySourceFile() * * @param $sourceUri * @param $targetUri * * @return bool */ protected function copySourceFile($sourceUri, $targetUri) { $bucket = $this->getSettings()->bucket; return (bool) @$this->_s3->copyObject($bucket, $sourceUri, $bucket, $targetUri, \S3::ACL_PUBLIC_READ); }
static function move_item($old_item, $new_item) { self::get_s3(); $old_filename = urldecode($old_item->relative_path()); $new_filename = urldecode($new_item->relative_path()); aws_s3::log("old filename: " . self::get_resource_url("fs/" . $old_filename) . ", " . "new filename: " . self::get_resource_url("fs/" . $new_filename)); //aws_s3::log($old_item->get_aws_s3_meta()); if ($old_item->s3_fullsize_uploaded) { aws_s3::log("Copying fullsize " . $old_filename . " to " . $new_filename); S3::copyObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("fs/" . $old_filename), module::get_var("aws_s3", "bucket_name"), self::get_resource_url("fs/" . $new_filename), $new_item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE); S3::deleteObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("fs/" . $old_filename)); } else { aws_s3::upload_item($new_item, aws_s3::UPLOAD_FULLSIZE); } if ($old_item->s3_resize_uploaded) { aws_s3::log("Copying resized " . $old_filename . " to " . $new_filename); S3::copyObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("rs/" . $old_filename), module::get_var("aws_s3", "bucket_name"), self::get_resource_url("rs/" . $new_filename), $new_item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE); S3::deleteObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("rs/" . $old_filename)); } else { aws_s3::upload_item($new_item, aws_s3::UPLOAD_RESIZE); } if ($old_item->s3_thumb_uploaded) { aws_s3::log("Copying thumbnail " . $old_filename . " to " . $new_filename); S3::copyObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("th/" . $old_filename), module::get_var("aws_s3", "bucket_name"), self::get_resource_url("th/" . $new_filename), $new_item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE); S3::deleteObject(module::get_var("aws_s3", "bucket_name"), self::get_resource_url("th/" . $old_filename)); } else { aws_s3::upload_item($new_item, aws_s3::UPLOAD_THUMB); } }