Blame view

WebRoot/plugins/ueditor/jsp/imageUp.jsp 2.66 KB
ad5081d3   孙向锦   初始化项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
      <%@ page language="java" contentType="text/html; charset=utf-8"
               pageEncoding="utf-8"%>
          <%@ page import="java.util.Properties" %>
          <%@ page import="java.util.List" %>
          <%@ page import="java.util.Iterator" %>
          <%@ page import="java.util.Arrays" %>
          <%@ page import="java.io.FileInputStream" %>
          <%@ page import="ueditor.Uploader" %>
          <%@ page import="java.io.File" %>
          <%@ page import="java.util.Map" %>
          <%@ page import="com.fh.util.*" %>
  
              <%
  
  request.setCharacterEncoding( Uploader.ENCODEING );
  response.setCharacterEncoding( Uploader.ENCODEING );
  
  String currentPath = request.getRequestURI().replace( request.getContextPath(), "" );
  
  File currentFile = new File( currentPath );
  
  currentPath = currentFile.getParent() + File.separator;
  //System.out.println("=================="+currentPath);
  //加载配置文件
  //String propertiesPath = request.getSession().getServletContext().getRealPath( currentPath + "config.properties" );
  String propertiesPath = request.getRealPath("/plugins/ueditor/jsp/config.properties");
  
  Properties properties = new Properties();
  
  try {
      properties.load( new FileInputStream( propertiesPath ) );
  } catch ( Exception e ) {
      //加载失败的处理
      e.printStackTrace();
  }
  
  List<String> savePath = Arrays.asList( properties.getProperty( "savePath" ).split( "," ) );
  
  
  //获取存储目录结构
  if ( request.getParameter( "fetch" ) != null ) {
  
      response.setHeader( "Content-Type", "text/javascript" );
  
      //构造json数据
      Iterator<String> iterator = savePath.iterator();
  
      String dirs = "[";
      while ( iterator.hasNext() ) {
  
          dirs += "'" + iterator.next() +"'";
  
          if ( iterator.hasNext() ) {
              dirs += ",";
          }
  
      }
      dirs += "]";
      response.getWriter().print( "updateSavePath( "+ dirs +" );" );
      return;
  
  }
  
  Uploader up = new Uploader(request);
  
  // 获取前端提交的path路径
  String dir = request.getParameter( "dir" );
  
  
  //普通请求中拿不到参数, 则从上传表单中拿
  if ( dir == null ) {
  	dir = up.getParameter("dir");
  }
  
  if ( dir == null || "".equals( dir ) ) {
  
      //赋予默认值
      dir = savePath.get( 0 );
  
      //安全验证
  } else if ( !savePath.contains( dir ) ) {
  
      response.getWriter().print( "{'state':'\\u975e\\u6cd5\\u4e0a\\u4f20\\u76ee\\u5f55'}" );
      return;
  
  }
  
  up.setSavePath( dir );
  String[] fileType = {".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp"};
  up.setAllowFiles(fileType);
  up.setMaxSize(500 * 1024); //单位KB
  up.upload();
  response.getWriter().print("{'original':'"+up.getOriginalName()+"','url':'"+up.getUrl()+"','title':'"+up.getTitle()+"','state':'"+up.getState()+"'}");
  %>