private function _get_remote_image()
 {
     $source = array();
     if (isset($_POST['source'])) {
         $source = $_POST['source'];
     } else {
         $source = $_GET['source'];
     }
     $item = array("state" => "", "url" => "", "size" => "", "title" => "", "original" => "", "source" => "");
     $date = date("Ymd");
     //远程抓取图片配置
     $config = array("savePath" => './' . C("UPLOADPATH") . "ueditor/{$date}/", "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp"), "maxSize" => 3000);
     $list = array();
     foreach ($source as $imgUrl) {
         $return_img = $item;
         $return_img['source'] = $imgUrl;
         $imgUrl = htmlspecialchars($imgUrl);
         $imgUrl = str_replace("&", "&", $imgUrl);
         //http开头验证
         if (strpos($imgUrl, "http") !== 0) {
             $return_img['state'] = $this->stateMap['ERROR_HTTP_LINK'];
             array_push($list, $return_img);
             continue;
         }
         //获取请求头
         if (sp_is_sae()) {
             //SAE下无效
             $heads = get_headers($imgUrl);
             //死链检测
             if (!(stristr($heads[0], "200") && stristr($heads[0], "OK"))) {
                 $return_img['state'] = $this->stateMap['ERROR_DEAD_LINK'];
                 array_push($list, $return_img);
                 continue;
             }
         }
         //格式验证(扩展名验证和Content-Type验证)
         $fileType = strtolower(strrchr($imgUrl, '.'));
         if (!in_array($fileType, $config['allowFiles']) || stristr($heads['Content-Type'], "image")) {
             $return_img['state'] = $this->stateMap['ERROR_HTTP_CONTENTTYPE'];
             array_push($list, $return_img);
             continue;
         }
         //打开输出缓冲区并获取远程图片
         ob_start();
         $context = stream_context_create(array('http' => array('follow_location' => false)));
         //请确保php.ini中的fopen wrappers已经激活
         readfile($imgUrl, false, $context);
         $img = ob_get_contents();
         ob_end_clean();
         //大小验证
         $uriSize = strlen($img);
         //得到图片大小
         $allowSize = 1024 * $config['maxSize'];
         if ($uriSize > $allowSize) {
             $return_img['state'] = $this->stateMap['ERROR_SIZE_EXCEED'];
             array_push($list, $return_img);
             continue;
         }
         //创建保存位置
         $savePath = $config['savePath'];
         if (!file_exists($savePath)) {
             mkdir("{$savePath}", 0777);
         }
         $file = uniqid() . strrchr($imgUrl, '.');
         //写入文件
         $tmpName = $savePath . $file;
         $file = C("TMPL_PARSE_STRING.__UPLOAD__") . "ueditor/{$date}/" . $file;
         if (strpos($file, "https") === 0 || strpos($file, "http") === 0) {
         } else {
             //local
             $host = (is_ssl() ? 'https' : 'http') . "://" . $_SERVER['HTTP_HOST'];
             $file = $host . $file;
         }
         if (sp_file_write($tmpName, $img)) {
             $return_img['state'] = 'SUCCESS';
             $return_img['url'] = $file;
             array_push($list, $return_img);
         } else {
             $return_img['state'] = $this->stateMap['ERROR_WRITE_CONTENT'];
             array_push($list, $return_img);
         }
     }
     return json_encode(array('state' => count($list) ? 'SUCCESS' : 'ERROR', 'list' => $list));
 }
 function avatar_update()
 {
     if (!empty($_SESSION['avatar'])) {
         $targ_w = intval($_POST['w']);
         $targ_h = intval($_POST['h']);
         $x = $_POST['x'];
         $y = $_POST['y'];
         $jpeg_quality = 90;
         $avatar = $_SESSION['avatar'];
         $avatar_dir = C("UPLOADPATH") . "avatar/";
         if (sp_is_sae()) {
             //TODO 其它存储类型暂不考虑
             $src = C("TMPL_PARSE_STRING.__UPLOAD__") . "avatar/{$avatar}";
         } else {
             $src = $avatar_dir . $avatar;
         }
         $avatar_path = $avatar_dir . $avatar;
         if (sp_is_sae()) {
             //TODO 其它存储类型暂不考虑
             $img_data = sp_file_read($avatar_path);
             $img = new \SaeImage();
             $size = $img->getImageAttr();
             $lx = $x / $size[0];
             $rx = $x / $size[0] + $targ_w / $size[0];
             $ty = $y / $size[1];
             $by = $y / $size[1] + $targ_h / $size[1];
             $img->crop($lx, $rx, $ty, $by);
             $img_content = $img->exec('png');
             sp_file_write($avatar_dir . $avatar, $img_content);
         } else {
             $image = new \Think\Image();
             $image->open($src);
             $image->crop($targ_w, $targ_h, $x, $y);
             $image->save($src);
         }
         $userid = sp_get_current_userid();
         $result = $this->users_model->where(array("id" => $userid))->save(array("avatar" => $avatar));
         $_SESSION['user']['avatar'] = $avatar;
         if ($result) {
             $this->success("头像更新成功!");
         } else {
             $this->error("头像更新失败!");
         }
     }
 }
 public function get_remote_image()
 {
     $uri = htmlspecialchars($_POST['upfile']);
     $uri = str_replace("&", "&", $uri);
     //远程抓取图片配置
     $config = array("savePath" => './' . C("UPLOADPATH") . "ueditor/", "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp"), "maxSize" => 3000);
     //忽略抓取时间限制
     set_time_limit(0);
     //ue_separate_ue  ue用于传递数据分割符号
     $imgUrls = explode("ue_separate_ue", $uri);
     $tmpNames = array();
     foreach ($imgUrls as $imgUrl) {
         //http开头验证
         if (strpos($imgUrl, "http") !== 0) {
             array_push($tmpNames, "error");
             continue;
         }
         //获取请求头
         if (!IS_SAE) {
             //SAE下无效
             $heads = get_headers($imgUrl);
             //死链检测
             if (!(stristr($heads[0], "200") && stristr($heads[0], "OK"))) {
                 array_push($tmpNames, "error");
                 continue;
             }
         }
         //格式验证(扩展名验证和Content-Type验证)
         $fileType = strtolower(strrchr($imgUrl, '.'));
         if (!in_array($fileType, $config['allowFiles']) || stristr($heads['Content-Type'], "image")) {
             array_push($tmpNames, "error");
             continue;
         }
         //打开输出缓冲区并获取远程图片
         ob_start();
         $context = stream_context_create(array('http' => array('follow_location' => false)));
         //请确保php.ini中的fopen wrappers已经激活
         readfile($imgUrl, false, $context);
         $img = ob_get_contents();
         ob_end_clean();
         //大小验证
         $uriSize = strlen($img);
         //得到图片大小
         $allowSize = 1024 * $config['maxSize'];
         if ($uriSize > $allowSize) {
             array_push($tmpNames, "error");
             continue;
         }
         //创建保存位置
         $savePath = $config['savePath'];
         if (!file_exists($savePath)) {
             mkdir("{$savePath}", 0777);
         }
         $file = date("Ymdhis") . uniqid() . strrchr($imgUrl, '.');
         //写入文件
         $tmpName = $savePath . $file;
         $file = C("TMPL_PARSE_STRING.__UPLOAD__") . "ueditor/" . $file;
         if (strpos($file, "https") === 0 || strpos($file, "http") === 0) {
         } else {
             //local
             $host = (is_ssl() ? 'https' : 'http') . "://" . $_SERVER['HTTP_HOST'];
             $file = $host . $file;
         }
         if (sp_file_write($tmpName, $img)) {
             array_push($tmpNames, $file);
         } else {
             array_push($tmpNames, "error");
         }
     }
     /**
      * 返回数据格式
      * {
      *   'url'   : '新地址一ue_separate_ue新地址二ue_separate_ue新地址三',
      *   'srcUrl': '原始地址一ue_separate_ue原始地址二ue_separate_ue原始地址三',
      *   'tip'   : '状态提示'
      * }
      */
     $response = "{'url':'" . implode("ue_separate_ue", $tmpNames) . "','tip':'远程图片抓取成功!','srcUrl':'" . $uri . "'}";
     exit($response);
 }