/**
  * 删除CSV
  *
  */
 public function action_del()
 {
     $id = (int) $this->getQuery('sid');
     $info = DB::select('uid', 'src_file')->from('imgup_movestore')->where('id', '=', $id)->fetch_row();
     if (!empty($info)) {
         $file = Io::strip(DOCROOT . 'src_csv/' . $info['uid'] . '/' . $info['src_file']);
         @unlink($file);
         DB::delete('imgup_movestore')->where('id', '=', $id)->execute();
         DB::delete('store_imgs')->where('sid', '=', $id)->where('uid', '=', $info['uid'])->execute();
     }
     $this->request->redirect('/admin/csvfile');
     $this->auto_render = false;
 }
 /**
  * 下载文件
  *
  * @param  integer  $fileId
  * @throws EGP_Exception
  */
 public function action_download()
 {
     $this->checkLogin();
     $id = (int) $this->getQuery('id');
     $app = trim($this->getQuery('app'));
     $info = DB::select()->from('imgup_movestore')->where('id', '=', $id)->where('uid', '=', $this->auth['uid'])->execute()->current();
     $filename = '';
     if ($app == 'source') {
         $filename = $info['src_file'];
         $savaname = Io::strip(DOCROOT . 'src_csv/' . $this->auth['uid'] . '/' . $filename);
     } else {
         $filename = $info['dest_file'];
         $savaname = Io::strip(DOCROOT . 'dest_csv/' . $this->auth['uid'] . '/' . $filename);
     }
     if (empty($info) || !is_readable($savaname)) {
         throw new Exception('指定的文件不存在或者已经被删除');
     }
     header('Content-Description: File Transfer');
     header('Content-Type: application/force-download');
     header('Content-Length: ' . filesize($savaname));
     header('Content-Disposition: attachment; filename=' . basename($info['csv_file']));
     readfile($savaname);
 }
 /**
  * 清空回收站
  */
 public function action_clear()
 {
     $rows = DB::select()->from('imgs')->where('userid', '=', (int) $this->auth['uid'])->where('recycle', '=', 1)->fetch_all();
     if (!empty($rows)) {
         $rows = new Arrayobj($rows);
         foreach ($rows as $row) {
             if ($row->userid == (int) $this->auth['uid']) {
                 // 添加图片到删除缓存表中
                 $url = 'http://' . $row->disk_id . '.wal8.com/';
                 $img_path = $row->disk_name . '/' . $row->picname;
                 $thumb_130 = $this->thumb->create2($img_path, 130, 130);
                 $data = array('img_url' => $url . $thumb_130, 'add_time' => time(), 'uid' => $this->auth['uid']);
                 @unlink(Io::strip(DOCROOT . $thumb_130));
                 $this->squid_img($data);
                 /*$thumb_120 = $thumb->create2($img_path, 120, 120);
                   $data['img_url'] = $url . $thumb_120;
                   $this->squid_img($data);
                   @unlink(Io::strip(DOCROOT.  $thumb_120));*/
                 $thumb_65 = $this->thumb->create2($img_path, 65, 65);
                 $data['img_url'] = $url . $thumb_65;
                 $this->squid_img($data);
                 @unlink(Io::strip(DOCROOT . $thumb_65));
                 $thumb_640 = $this->thumb->create2($img_path, 640, 640, 's');
                 $data['img_url'] = $url . $thumb_640;
                 $this->squid_img($data);
                 @unlink(Io::strip(DOCROOT . $thumb_640));
                 $data['img_url'] = $url . $img_path;
                 $this->squid_img($data);
                 // 删除评论
                 DB::delete('comments')->where('item_id', '=', $row->id)->where('app', '=', 'img')->execute();
                 // 删除图片记录
                 DB::delete('imgs')->where('id', '=', $row->id)->execute();
                 @unlink(Io::strip(DOCROOT . $row->disk_name . '/' . $row->picname));
                 // 删除标签
                 $tag = new tags();
                 $tag->del($row->id, 'app');
             }
         }
     }
     echo 'success';
     //$this->request->redirect('/category/list?recycle=1');
     $this->auto_render = false;
 }
Beispiel #4
0
 /**
  * 编辑图片
  */
 public function action_picedit()
 {
     $this->checklogin();
     $this->template->pid = $pid = (int) $this->getRequest('pid');
     $this->template->zoom = $zoom = trim($this->getQuery('zoom'));
     $this->template->info = $info = ORM::factory('img')->where('imgs.userid', '=', (int) $this->auth['uid'])->where('imgs.id', '=', $pid)->find();
     if (empty($info->picname)) {
         $this->show_message('非法访问', 0, array(), true);
     }
     $url = "http://" . $info->disk_id . '.wal8.com/';
     $picname = $info->disk_name . '/' . $info->picname;
     $thumb = new Thumb();
     if ($zoom == 'medium') {
         $picname = $thumb->create($picname, 640, 640, 's');
     } elseif ($zoom == 'thumb') {
         $picname = $thumb->create($picname, 130, 130);
     }
     $this->template->picname = $url . $picname;
     if ($this->isPost()) {
         $editName = trim($this->getPost('name'));
         $pid = (int) $this->getPost('pid');
         $set['custom_name'] = $editName;
         if (!empty($_FILES['newfile']['name'])) {
             $disks = ORM::factory('img_disk')->where('is_use', '=', 1)->find();
             $save_dir = ORM::factory('user', (int) $this->auth['uid'])->save_dir;
             $savePath = DOCROOT . '' . $disks->disk_name . '/' . $save_dir . '/';
             $upload = new Upload(array('size' => 2024));
             try {
                 $upload->set_path($savePath);
                 $result = $upload->save($_FILES['newfile']);
                 //$set['picname'] = $result['saveName'];
                 $set['filename'] = $result['name'];
                 $set['custom_name'] = $result['name'];
                 $set['filesize'] = $result['size'];
                 $picPath = pathinfo($info->disk_name . '/' . $info->picname);
                 $img_dir = '/s/';
                 $img_dir2 = '/thumbnails/';
                 if (!empty($this->img_size)) {
                     foreach ($this->img_size as $key => $v) {
                         //标准图路径
                         $zoomPath = $picPath['dirname'] . $img_dir . $picPath['filename'] . $v;
                         @unlink(Io::strip(DOCROOT . $zoomPath . $picPath['extension']));
                         @unlink(Io::strip(DOCROOT . $zoomPath . 'jpg'));
                         //缩略图路径
                         $thumbPath = $info->disk_name . $img_dir2 . $picPath['filename'] . $v;
                         @unlink(Io::strip(DOCROOT . $thumbPath . $picPath['extension']));
                         @unlink(Io::strip(DOCROOT . $thumbPath . 'jpg'));
                         @unlink(Io::strip(DOCROOT . $thumbPath . 'gif'));
                     }
                     @unlink(Io::strip(DOCROOT . $info->disk_name . '/' . $info->picname));
                     $saveName = $disks->disk_name . '/' . $save_dir . '/' . $result['saveName'];
                     rename($saveName, DOCROOT . $info->disk_name . '/' . $info->picname);
                     $saveName = $disks->disk_name . '/' . $save_dir . '/' . $info->picname;
                     $url = 'http://' . $info->disk_id . '.wal8.com/';
                     $data = array('img_url' => $url . $this->thumb->create($saveName, 130, 130), 'add_time' => time(), 'uid' => $this->auth['uid']);
                     $this->squid_img($data);
                     $data['img_url'] = $url . $this->thumb->create($saveName, 640, 640, 's');
                     $this->squid_img($data);
                     $data['img_url'] = $url . $this->thumb->create($saveName, 120, 120);
                     $this->squid_img($data);
                     $data['img_url'] = $url . $saveName;
                     $this->squid_img($data);
                 }
             } catch (Exception $e) {
                 $this->show_message($e->getMessage(), 0, array(), true);
             }
         }
         DB::update('imgs')->set($set)->where('id', '=', $pid)->execute();
         $sum = DB::select(DB::expr("sum(filesize) as sums"))->from('imgs')->where('userid', '=', $this->auth['uid'])->execute()->get('sums');
         DB::update('users')->set(array('use_space' => $sum))->where('uid', '=', $this->auth['uid'])->execute();
         ORM::factory('user')->upcache($this->auth['uid']);
         $links[] = array('text' => '重载图片编辑', 'href' => '/pic/picedit?pid=' . $pid);
         $this->show_message('修改图片处理成功', 1, $links, true);
     }
 }
 /**
  * 自动远程保存图片
  *
  */
 public function action_saveimg()
 {
     $source = $this->getQuery('src');
     if (!URL::ping($source)) {
         echo $source;
         die;
     }
     $title = trim($this->getQuery('title'));
     $data = @file_get_contents($source);
     $filename = basename($source);
     $extension = strtolower(strtolower(substr(strrchr($filename, '.'), 1)));
     $saveName = str_replace('.', '', microtime(true));
     // 保存的文件名
     $disk = ORM::factory('img_disk')->where('is_use', '=', 1)->find();
     $save_dir = ORM::factory('user', $this->auth['uid'])->save_dir;
     $savefile = Io::strip(Io::mkdir(DOCROOT . $disk->disk_name . '/' . $save_dir) . '/' . $saveName . ".{$extension}");
     $filesize = @file_put_contents($savefile, $data);
     //保存文件,返回文件的size
     if ($filesize == 0) {
         //保存失败
         @unlink($savefile);
         throw new Exception('文件保存到本地目录时失败');
     }
     list($w, $h, $t, ) = getimagesize($savefile);
     $filetype = image_type_to_mime_type($t);
     if (!preg_match('/^image\\/.+/i', $filetype)) {
         throw new Exception('转存文件并非有效的图片文件');
     }
     $category = ORM::factory('img_category')->where('cate_name', '=', '产品搬家')->where('uid', '=', $this->auth['uid'])->find();
     $cate = new Category();
     if (empty($category->cate_name)) {
         $cate_id = $cate->add(array('cate_name' => '产品搬家', 'uid' => $this->auth['uid']));
     } else {
         $cate_id = $category->cate_id;
     }
     $movehomeSession = Session::instance()->get('movehome_id', false);
     if (!empty($title)) {
         if (empty($movehomeSession)) {
             $cate_id = $cate->add(array('cate_name' => $title, 'uid' => $this->auth['uid'], 'parent_id' => $cate_id));
             Session::instance()->set('movehome_id', $cate_id);
         } else {
             $cate_id = $movehomeSession;
         }
     }
     $img = ORM::factory('img');
     $img->picname = $saveName . ".{$extension}";
     $img->filename = $filename;
     $img->filesize = $filesize;
     $img->userid = $this->auth['uid'];
     $img->cate_id = $cate_id;
     $img->disk_id = $disk->disk_domain;
     $img->disk_name = $disk->disk_name . '/' . $save_dir;
     $img->custom_name = $saveName;
     $img->save();
     $url = "http://" . $disk->disk_domain . '.wal8.com/' . $disk->disk_name . '/' . $save_dir . '/' . $saveName . ".{$extension}";
     // 统计数据
     $num = $img->where('userid', '=', $this->auth['uid'])->where('cate_id', '=', $cate_id)->count_all();
     DB::update('img_categories')->set(array('img_num' => $num))->where('uid', '=', $this->auth['uid'])->where('cate_id', '=', $cate_id)->execute();
     $rows = DB::select(array('sum("filesize")', 'total_size'), array('count("userid")', 'total_num'))->from('imgs')->where('userid', '=', $this->auth['uid'])->execute()->current();
     DB::update('users')->set(array('use_space' => $rows['total_size'], 'count_img' => $rows['total_num']))->where('uid', '=', $this->auth['uid'])->execute();
     $result = array('status' => true, 'source' => $source, 'url' => $url);
     echo $url;
     $this->auto_render = false;
 }