/** * Image upload * @param $group * @param bool $multi */ protected function image_upload($group, $multi = true) { $id = $this->request->param('param'); if ($multi) { $fu = new Fileuploaders($group, $this->user->id, $id); if ($fu->image_upload()) { $this->json = View::factory('backend/v_image_multi', $fu->get_data()); } else { $this->json = Message::view(Message::ERROR, $fu->errors()); } } else { $fu = new Fileuploader($group, $this->user->id, $id); if ($fu->image_upload()) { $this->json = View::factory('backend/v_image_single', $fu->get_data()); } else { $this->json = Message::view(Message::ERROR, $fu->errors()); } } }
/** * Save * @param Validation $validation * @return ORM */ public function save(Validation $validation = null) { parent::save($validation); if (Request::get('action') == 'add') { // $this->fimage = Fileuploader::get_fimage('app.project_logo'); Fileuploaders::get_fimage('shop.product_images', Auth::instance()->get_user()->id, $this->id); } if ($this->slug == '') { $this->slug = $this->get_unique_slug($this->title); } return parent::save($validation); }
/** * Remove files of images from dir * * @param $group * @param $id */ public static function remove_fimage($group, $id) { if (self::$_cache_config === NULL) { self::$_cache_config = Kohana::$config->get($group); } if (self::$_cache_fs === NULL) { self::$_cache_fs = new Symfony\Component\Filesystem\Filesystem(); } $img_many = ORM::factory(self::$_cache_config['model_many'])->where(self::$_cache_config['foreign_key'], '=', $id)->find_all(); foreach ($img_many as $img_item) { $full_name = UPLOAD_DIR . self::$_cache_config['dir'] . DS . $img_item->{self::$_cache_config['fn']}; if (is_file($full_name)) { // Remove image from dir self::$_cache_fs->remove($full_name); // If image has thumbnails if (self::$_cache_config['thumbnails']) { foreach (self::$_cache_config['thumbnails'] as $thumbnail) { // Remove thumbnails images from dir self::$_cache_fs->remove(UPLOAD_DIR . self::$_cache_config['dir'] . DS . $thumbnail['dir'] . DS . $img_item->{self::$_cache_config['fn']}); } } } } }
foreach ($actions as $key => $action) { $url[$key] = Route::url('ajax', ['module' => $module, 'controller' => $controller, 'action' => $action, 'param' => $obj['id']]); } $group = $module . '.' . $config_img; $fn = Config::get($group . '.fn'); ?> <div class="form-group"> <?php echo TB_Form::label(__('shop.images')); ?> <div class="controls col-sm-10"> <div id="fileuploads-info"></div> <div id="fileuploads-result"> <?php echo $obj['id'] ? Fileuploaders::v_image($group, $obj['id'], $obj['is_edit']) : Fileuploaders::v_image($group, $user->id); ?> </div> <div class="btn btn-default fileupload-button"> <i class="fa fa-folder-open fa-fw"></i> <?php echo __('shop.select_image'); ?> <input name="<?php echo $fn; ?> " id="fileuploads" type="file" data-url="<?php echo $url['upload']; ?> " multiple> </div>