Ejemplo n.º 1
0
 /**
  *  Upload image
  *  @param string $mainFolder - name of th block in Config/images.php
  *  @return string            - filename
  */
 public static function uploadImage($mainFolder)
 {
     if (!Arr::get($_FILES['file'], 'name')) {
         return false;
     }
     $need = Config::get('images.' . $mainFolder);
     if (!$need) {
         return false;
     }
     $ext = end(explode('.', $_FILES['file']['name']));
     $filename = md5($_FILES['file']['name'] . '_' . $mainFolder . time()) . '.' . $ext;
     foreach ($need as $one) {
         $path = HOST . HTML::media('/images/' . $mainFolder . '/' . Arr::get($one, 'path'));
         Files::createFolder($path, '0777');
         $file = $path . '/' . $filename;
         $image = Image::factory($_FILES['file']['tmp_name']);
         if (Arr::get($one, 'resize')) {
             $image->resize(Arr::get($one, 'width'), Arr::get($one, 'height'), Image::INVERSE);
         }
         if (Arr::get($one, 'crop')) {
             $image->crop(Arr::get($one, 'width'), Arr::get($one, 'height'));
         }
         $image->save($file);
     }
     return $filename;
 }
Ejemplo n.º 2
0
 function deleteImageAction()
 {
     $id = (int) Route::param('id');
     if (!$id) {
         Message::GetMessage(0, 'Данные не существуют!');
         HTTP::redirect('backend/' . Route::controller() . '/index');
     }
     $page = DB::select()->from($this->tablename)->where('id', '=', $id)->find();
     if (!$page) {
         Message::GetMessage(0, 'Данные не существуют!');
         HTTP::redirect('backend/' . Route::controller() . '/index');
     }
     Files::deleteImage($this->image, $page->image);
     DB::update($this->tablename)->set(array('image' => null))->where('id', '=', $id)->execute();
     Message::GetMessage(1, 'Данные удалены!');
     HTTP::redirect('backend/' . Route::controller() . '/edit/' . $id);
 }
Ejemplo n.º 3
0
 public function upload_imagesAction()
 {
     if (empty($_FILES['file'])) {
         die('No File!');
     }
     $confirm = false;
     $arr = explode('/', Arr::get($_SERVER, 'HTTP_REFERER'));
     $id_good = (int) end($arr);
     $headers = HTML::emu_getallheaders();
     if (array_key_exists('Upload-Filename', $headers)) {
         //                $data = file_get_contents('php://input');
         $name = $headers['Upload-Filename'];
     } else {
         $name = $_FILES['file']['name'];
     }
     $name = explode('.', $name);
     $ext = strtolower(end($name));
     if (!in_array($ext, Config::get('images.types'))) {
         die('Not image!');
     }
     $filename = Files::uploadImage('catalog');
     $has_main = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('catalog_images')->where('catalog_id', '=', $id_good)->where('main', '=', 1)->count_all();
     $data = array('catalog_id' => $id_good, 'image' => $filename);
     if (!$has_main) {
         $data['main'] = 1;
     }
     $keys = $values = array();
     foreach ($data as $key => $value) {
         $keys[] = $key;
         $values[] = $value;
     }
     DB::insert('catalog_images', $keys)->values($values)->execute();
     die(json_encode(array('confirm' => true)));
 }