fileUp.jsp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <%@page import="java.io.File"%>
  2. <%@page import="java.util.Properties"%>
  3. <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
  4. <%@ page import="ueditor.Uploader" %>
  5. <%@ page import="java.io.FileInputStream" %>
  6. <%
  7. request.setCharacterEncoding( Uploader.ENCODEING );
  8. response.setCharacterEncoding( Uploader.ENCODEING );
  9. String currentPath = request.getRequestURI().replace( request.getContextPath(), "" );
  10. File currentFile = new File( currentPath );
  11. currentPath = currentFile.getParent() + File.separator;
  12. //加载配置文件
  13. //String propertiesPath = request.getSession().getServletContext().getRealPath( currentPath + "config.properties" );
  14. String propertiesPath = request.getRealPath("/plugins/ueditor/jsp/config.properties");
  15. Properties properties = new Properties();
  16. try {
  17. properties.load( new FileInputStream( propertiesPath ) );
  18. } catch ( Exception e ) {
  19. //加载失败的处理
  20. e.printStackTrace();
  21. }
  22. Uploader up = new Uploader(request);
  23. up.setSavePath("upload"); //保存路径
  24. String[] fileType = {".rar" , ".doc" , ".docx" , ".zip" , ".pdf" , ".txt" , ".swf", ".wmv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".mov", ".wmv", ".mp4"}; //允许的文件类型
  25. up.setAllowFiles(fileType);
  26. up.setMaxSize(500 * 1024); //允许的文件最大尺寸,单位KB
  27. up.upload();
  28. response.getWriter().print("{'url':'"+up.getUrl()+"','fileType':'"+up.getType()+"','state':'"+up.getState()+"','original':'"+up.getOriginalName()+"'}");
  29. %>