public function setcategoryimage()
 {
     $catid = intval($_GET['catid']);
     $upload = new \Core\UploadImage();
     if ($image = $upload->saveImage()) {
         $this->t('service_category')->where(array('catid' => $catid))->update(array('pic' => $image['attachment']));
         $this->showAjaxReturn(array('pic' => image($image['attachment'])));
     } else {
         $this->showAjaxError(-1, 'upload failed(' . $upload->error . ')');
     }
 }
 /**
  * 设置店铺图片
  */
 public function setimage()
 {
     $upload = new \Core\UploadImage();
     if ($filedata = $upload->saveImage()) {
         $shopid = intval($_GET['shopid']);
         $this->t('shop')->where(array('uid' => $this->uid, 'shopid' => $shopid))->update(array('pic' => $filedata['attachment']));
         $this->showAppData(array('url' => image($filedata['attachment'])));
     } else {
         $this->showAppError(-1, 'upload failed');
     }
 }
 public function upload()
 {
     $upload = new \Core\UploadImage();
     if ($photo = $upload->saveImage()) {
         $photo['uid'] = $this->uid;
         $photo['uptime'] = time();
         $this->t('photo')->insert($photo);
         $this->showAjaxReturn(array('url' => C('ATTACHURL') . $photo['attachment'], 'attachment' => $photo['attachment']));
     } else {
         $this->showAjaxError(-1, 'upload Error');
     }
 }
 public function setavatar()
 {
     $upload = new \Core\UploadImage();
     if ($filedata = $upload->saveImage()) {
         $filedata['uid'] = $this->uid;
         $filedata['username'] = $this->username;
         $filedata['uptime'] = time();
         $filedata['photoid'] = $this->t('photo')->insert($filedata, true);
         //裁剪图片
         $sourceImg = C('ATTACHDIR') . $filedata['attachment'];
         $avatardir = C('AVATARDIR') . $this->uid;
         $avatarsmall = $this->uid . '_avatar_small.jpg';
         $avatarmiddle = $this->uid . '_avatar_middle.jpg';
         $avatarbig = $this->uid . '_avatar_big.jpg';
         @mkdir($avatardir, 0777, true);
         $image = new Image($sourceImg);
         if ($image->width() > $image->height()) {
             $w = $image->height();
             $x = ($image->width() - $image->height()) / 2;
             $y = 0;
         } else {
             $w = $image->width();
             $x = 0;
             $y = ($image->height() - $image->width()) / 2;
         }
         $image->crop($w, $w, $x, $y, 150, 150);
         $image->save($avatardir . '/' . $avatarbig);
         $image = new Image($sourceImg);
         $image->crop($w, $w, $x, $y, 50, 50);
         $image->save($avatardir . '/' . $avatarmiddle);
         $image = new Image($sourceImg);
         $image->crop($w, $w, $x, $y, 30, 30);
         $image->save($avatardir . '/' . $avatarsmall);
         $this->t('member')->where(array('uid' => $this->uid))->update(array('avatarstatus' => 1));
         $this->showAppData(array('url' => image($filedata['attachment'])));
     } else {
         $this->showAppError(-1, 'upload error', array('errno' => $upload->error));
     }
 }