/**
 +----------------------------------------------------------
 * 上传一个文件
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param mixed $name 数据
 * @param string $value  数据表名
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 private function save($file)
 {
     $filename = $file['savepath'] . $file['savename'];
     if (!$this->uploadReplace && is_file($filename)) {
         // 不覆盖同名文件
         $this->error = '文件已经存在!' . $filename;
         return false;
     }
     if (!move_uploaded_file($file['tmp_name'], auto_charset($filename, 'utf-8', 'gbk'))) {
         $this->error = '文件上传保存错误!';
         return false;
     }
     if ($this->thumb) {
         // 生成图像缩略图
         vendor("yu_image");
         $img = new yu_image();
         // 等比缩放
         $img->param($filename)->thumb($file['savepath'] . $this->thumbFile, $this->thumbMaxWidth, 1000, 0);
         //            import("ORG.Util.Image");
         //            $image =  Image::getImageInfo($filename);
         //			dump($image);
         //            if(false !== $image) {
         //                //是图像文件生成缩略图
         //                $thumbWidth		=	explode(',',$this->thumbMaxWidth);
         //                $thumbHeight		=	explode(',',$this->thumbMaxHeight);
         //                $thumbPrefix		=	explode(',',$this->thumbPrefix);
         //                $thumbSuffix = explode(',',$this->thumbSuffix);
         //                $thumbFile			=	explode(',',$this->thumbFile);
         //                $thumbPath    =  $this->thumbPath?$this->thumbPath:$file['savepath'];
         //                for($i=0,$len=count($thumbWidth); $i<$len; $i++) {
         //                    $thumbname	=	$thumbPath.$thumbPrefix[$i].substr($file['savename'],0,strrpos($file['savename'], '.')).$thumbSuffix[$i].'.'.$file['extension'];
         //                   dump($filename);dump($thumbname);
         //					$xxx = Image::thumb($filename,$thumbname,'',$thumbWidth[$i],$thumbHeight[$i],true);
         //					dump($xxx);
         //                }
         //                if($this->thumbRemoveOrigin) {
         //                    // 生成缩略图之后删除原图
         //                    unlink($filename);
         //                }
         //            }
     }
     if ($this->zipImags) {
         // TODO 对图片压缩包在线解压
     }
     return true;
 }
 function saveThumb()
 {
     //头像大方快的宽高
     $targ_w = 120;
     $targ_h = 120;
     //头像小方块的宽高
     $small_w = 50;
     $small_h = 50;
     //图像质量
     $jpeg_quality = 80;
     $src_arr = explode("?", $_POST['bigImage']);
     $src = $src_arr[0];
     $src = str_ireplace(SITE_URL, '.', $src);
     //获取图片的扩展名。来选择使用什么函数
     if ($arr = @getimagesize($src)) {
         $ext = image_type_to_extension($arr[2], false);
     } else {
         $this->error('对不起,GD库不存在或远程图片不存在');
     }
     $func = $ext != 'jpg' ? 'imagecreatefrom' . $ext : 'imagecreatefromjpeg';
     $img_r = call_user_func($func, $src);
     //开始切割大方块头像
     $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
     $x = $targ_h / $_POST['txt_Zoom'];
     imagecopyresampled($dst_r, $img_r, 0, 0, $_POST['txt_left'] / $_POST['txt_Zoom'], $_POST['txt_top'] / $_POST['txt_Zoom'], $targ_w, $targ_h, $x, $x);
     $path = SITE_PATH . "data/thumb/";
     $filename = $path . 'xxx_s.jpg';
     $face_path = getFacePath($this->mid);
     mkdir($face_path, 0777, true);
     $middle_name = $face_path . $this->mid . "_middle_face.jpg";
     //中图
     imagejpeg($dst_r, $middle_name);
     //生成中图
     imagedestroy($dst_r);
     imagedestroy($img_r);
     $small_name = $face_path . $this->mid . "_small_face.jpg";
     //小图
     vendor("yu_image");
     $img = new yu_image();
     $img->param($middle_name)->thumb($small_name, $small_w, $small_h, 0);
     //缩出小图
     //添加一条动态
     $body_data["src"] = getUserFace($this->mid);
     $this->api->feed_publish("head", $title_data, $body_data);
     setScore($this->mid, 'update_face');
     $this->redirect("/Home/index");
 }
 public function set_face()
 {
     //暂时先这么写,应该加到API接口里面去。
     $path = SITE_PATH . "/data/thumb/";
     $filename = $path . 'xxx_s.jpg';
     $face_path = getFacePath($this->mid);
     $middle_name = $face_path . "/" . $this->mid . "_middle_face.jpg";
     //中图
     imagejpeg($dst_r, $middle_name);
     //生成中图
     imagedestroy($dst_r);
     imagedestroy($img_r);
     $small_name = $face_path . "/" . $this->mid . "_small_face.jpg";
     //小图
     vendor("yu_image");
     $img = new yu_image();
     $img->param($middle_name)->thumb($small_name, $small_w, $small_h, 0);
     //缩出小图
     //添加一条动态
     $body_data["src"] = getUserFace($this->mid);
     $this->api->feed_publish("head", $title_data, $body_data);
 }