public function action_upload($folder, $sub = null)
 {
     if (\Fuel\Core\Input::method() == 'POST') {
         try {
             \Fuel\Core\DB::start_transaction();
             $val = Model_Filemanager::validate('create');
             if ($val->run()) {
                 $config = array('path' => "/var/www/html/" . $this->_dir . "/" . $folder . "/" . $sub . DS, 'ext_whitelist' => array('jpg', 'jpeg', 'png'), 'file_chmod' => 0777, 'auto_rename' => true, 'overwrite' => true, 'randomize' => true, 'create_path' => true);
                 Upload::process($config);
                 $img = '';
                 if (Upload::is_valid()) {
                     Upload::save();
                     $img = Upload::get_files()[0];
                 }
                 if (!\Fuel\Core\Input::post('id')) {
                     $file = Model_Filemanager::forge(array('folder' => $folder, 'key' => Input::post('key'), 'value' => $img['saved_as'], 'photographer' => \Fuel\Core\Input::post('photographer'), 'price' => \Fuel\Core\Input::post('price'), 'usage' => \Fuel\Core\Input::post('usage'), 'source' => \Fuel\Core\Input::post('source')));
                 } else {
                     $file = Model_Filemanager::find_by_id(\Fuel\Core\Input::post('id'));
                     if ($img == '') {
                         $img = $file->value;
                     }
                     if ($file) {
                         $file->set(array('folder' => $folder, 'key' => Input::post('key'), 'value' => $img, 'photographer' => \Fuel\Core\Input::post('photographer'), 'price' => \Fuel\Core\Input::post('price'), 'usage' => \Fuel\Core\Input::post('usage'), 'source' => \Fuel\Core\Input::post('source')));
                     } else {
                         throw new Exception('File not found!');
                     }
                 }
                 if ($file and $file->save()) {
                     DB::commit_transaction();
                     \Fuel\Core\Session::set_flash('success', 'Upload success');
                 } else {
                     throw new Exception('Cannot save into database!');
                 }
             } else {
                 throw new Exception($val->show_errors());
             }
         } catch (Exception $e) {
             DB::rollback_transaction();
             \Fuel\Core\Session::set_flash('error', $e->getMessage());
         }
     }
     \Fuel\Core\Response::redirect(\Fuel\Core\Uri::create('filemanager/folder/' . $folder));
 }
Beispiel #2
0
 public function get_image()
 {
     try {
         if (\Fuel\Core\Input::get('image')) {
             $model = Model_Filemanager::find('last', array('where' => array('key' => \Fuel\Core\Input::get('image'))));
             if ($model) {
                 $v = $model;
                 $data = array('id' => $v->id, 'key' => $v->key, 'value' => $v->value, 'photographer' => $v->photographer, 'price' => $v->price, 'usage' => $v->usage, 'source' => $v->source);
                 $this->_response['result'] = true;
                 $this->_response['data'] = $data;
             } else {
                 throw new Exception('Image not found.');
             }
         } else {
             throw new Exception('Parameter image not given');
         }
     } catch (Exception $e) {
         $this->_response['message'] = $e->getMessage();
     }
     return $this->response($this->_response);
 }
Beispiel #3
0
                        <button type="submit" class="btn btn-primary">
                            <i class="fa fa-upload"></i> Send
                        </button>

                    </div>
                </div>
            </form>
            <div class="clearfix"></div>
        </div>
        <div id="wall">
            <?php 
try {
    foreach ($all as $k => $v) {
        if (is_int($k)) {
            $name = '';
            $model = Model_Filemanager::find_by_value($v);
            if ($model and $model->deleted_at == null) {
                $name = $model->key;
                $v = str_replace('150x150_', '', $v);
                echo '<div class=" col-lg-2"><div class="thumbnail">';
                echo \Fuel\Core\Html::img('images/file/' . $folder . '/270x270/crop/?image=' . $v);
                echo '<div class="caption">';
                echo '<p class="img_name">' . $name . '</p>';
                echo '<p>' . \Fuel\Core\Html::anchor('images/file/' . $folder . '/150x150/crop/?image=' . $v . '&action=view', '<i class="fa fa-eye-open"></i> ดูข้อมูล', array('class' => 'btn btn-info view')) . '</p>';
                echo '<p>' . \Fuel\Core\Html::anchor('images/file/' . $folder . '/150x150/crop/?image=' . $v . '&action=delete', '<i class="fa fa-times"></i> ลบ', array('class' => 'btn btn-danger')) . '</p>';
                echo '</div>';
                echo '</div></div> ';
            }
        }
    }
} catch (Exception $e) {
Beispiel #4
0
 public function action_file($folder = null, $size = null, $crop = 'no')
 {
     try {
         if (is_null($folder)) {
             throw new Exception('Folder name is not given!');
         }
         if (is_null($size)) {
             throw new Exception('Image file name is not given!');
         }
         if (!strpos($size, 'x')) {
             throw new Exception('Image size is not given!');
         }
         if (!\Fuel\Core\Input::get('image')) {
             throw new Exception('Image is not given!');
         }
         $file = \Fuel\Core\Input::get('image');
         /** @var  $upload_path */
         $upload_path = '/var/www/html/' . $this->_dir;
         /** @var  $file_path */
         $file_path = $folder . '/' . $file;
         /** @var  $real_path */
         $real_path = $upload_path . '/' . $file_path;
         /** @var  $new_name */
         $new_name = $size . '_' . $file;
         /** @var  $resize_path : Path for resize only */
         $resize_path = $upload_path . '/' . $folder . '/resize/';
         /** @var  $resize_file */
         $resize_file = $upload_path . '/' . $folder . '/resize/' . $new_name;
         /** @var  $crop_path : Path for crop only */
         $crop_path = $upload_path . '/' . $folder . '/crop/';
         /** @var  $crop_file */
         $crop_file = $upload_path . '/' . $folder . '/crop/' . $new_name;
         /** @var  $image */
         $image = \Fuel\Core\Image::forge(array('driver' => 'gd', 'bgcolor' => null, 'quality' => 100));
         /** @var  $where_are_file */
         $where_are_file = '';
         /** @var  $where_are_path */
         $where_are_path = '';
         if ($crop == 'no') {
             $where_are_file = $resize_file;
             $where_are_path = $resize_path;
         } else {
             $where_are_file = $crop_file;
             $where_are_path = $crop_path;
         }
         if (!file_exists($where_are_file)) {
             /**
              *  Check if not dir then make it.
              */
             if (!is_dir($where_are_path)) {
                 if (!mkdir($where_are_path, 0777)) {
                     throw new Exception('Permission denied!');
                 }
             }
             /** @var  $size */
             $size = explode('x', $size);
             if ($crop == 'crop') {
                 /**
                  *  Chaining to crop_resize() function
                  */
                 $image->load($real_path)->crop_resize($size[0], $size[1])->save($where_are_file);
             } else {
                 /**
                  *  Chaining to resize() function
                  */
                 $image->load($real_path)->resize($size[0], $size[1], true, false)->save($where_are_file);
             }
             /**
              *  Load file and output image.
              */
             $image->load($where_are_file)->output();
         } else {
             /**
              *  If file exist force output to show image.
              */
             if (\Fuel\Core\Input::get('action') == 'delete') {
                 if (\Auth\Auth::instance()->get('group') == 100) {
                     $model = Model_Filemanager::find_by_value($file);
                     if ($model) {
                         $model->deleted_at = time();
                         $model->value = null;
                         if ($model->save()) {
                             \Fuel\Core\File::delete($where_are_file);
                             \Fuel\Core\File::delete($real_path);
                             \Fuel\Core\Response::redirect('filemanager/folder/' . $folder);
                         } else {
                             throw new Exception('Cannot delete in database!');
                         }
                     } else {
                         throw new Exception('Image not found!');
                     }
                 } else {
                     throw new Exception('You are not an Administrator!');
                 }
             } else {
                 $image->load($where_are_file)->output();
             }
         }
     } catch (Exception $e) {
         /** @var  $error */
         $error = '<ul>';
         $error .= '<li>' . $e->getLine() . '</li>';
         $error .= '<li>' . $e->getFile() . '</li>';
         $error .= '<li>' . $e->getMessage() . '</li>';
         $error .= '</ul>';
         return $error;
     }
     exit;
 }