|
@@ -0,0 +1,71 @@
|
|
|
+<%@ page language="java" contentType="text/html; charset=UTF-8"
|
|
|
+ pageEncoding="UTF-8"%>
|
|
|
+<%@ page import="java.io.*,java.util.*, javax.servlet.*" %>
|
|
|
+<%@ page import="javax.servlet.http.*" %>
|
|
|
+<%@ page import="org.apache.commons.fileupload.*" %>
|
|
|
+<%@ page import="org.apache.commons.fileupload.disk.*" %>
|
|
|
+<%@ page import="org.apache.commons.fileupload.servlet.*" %>
|
|
|
+<%@ page import="org.apache.commons.io.output.*" %>
|
|
|
+<%@ page import="org.apache.commons.io.FilenameUtils" %>
|
|
|
+<%@ page import="java.util.UUID" %>
|
|
|
+<%
|
|
|
+ File file ;
|
|
|
+ int maxFileSize = 5000 * 1024;
|
|
|
+ int maxMemSize = 5000 * 1024;
|
|
|
+ String photoPath =
|
|
|
+ this.getServletConfig().getServletContext().getRealPath("/userUpload/");
|
|
|
+ File filePhotoPath = new File(photoPath);
|
|
|
+ if(!filePhotoPath.isDirectory()) {
|
|
|
+ filePhotoPath.mkdir();
|
|
|
+ }
|
|
|
+
|
|
|
+ String contentType = request.getContentType();
|
|
|
+ if ((contentType.indexOf("multipart/form-data") >= 0)) {
|
|
|
+
|
|
|
+ DiskFileItemFactory factory = new DiskFileItemFactory();
|
|
|
+ factory.setSizeThreshold(maxMemSize);
|
|
|
+ factory.setRepository(new File(photoPath));
|
|
|
+ ServletFileUpload upload = new ServletFileUpload(factory);
|
|
|
+ upload.setSizeMax( maxFileSize );
|
|
|
+ try{
|
|
|
+ List fileItems = upload.parseRequest(request);
|
|
|
+ Iterator i = fileItems.iterator();
|
|
|
+ while ( i.hasNext () )
|
|
|
+ {
|
|
|
+ FileItem fi = (FileItem)i.next();
|
|
|
+ if ( !fi.isFormField () ) {
|
|
|
+ String fieldName = fi.getFieldName();
|
|
|
+ String fileName = fi.getName();
|
|
|
+ boolean isInMemory = fi.isInMemory();
|
|
|
+ long sizeInBytes = fi.getSize();
|
|
|
+ if(fieldName.equals("myFile")){
|
|
|
+ String ext = FilenameUtils.getExtension(fileName);
|
|
|
+ if((ext.toUpperCase().equals("JPG"))||(ext.toUpperCase().equals("JPEG"))||(ext.toUpperCase().equals("PNG"))||(ext.toUpperCase().equals("GIF"))){
|
|
|
+ String filename = UUID.randomUUID().toString() + "."+ ext;
|
|
|
+ file = new File(photoPath+"//"+filename);
|
|
|
+ fi.write(file);
|
|
|
+ out.println("<script>parent.get_file2('/userUpload/"+filename+"')</script>");
|
|
|
+ }else{
|
|
|
+ out.println("<script>parent.file_result2('图片上传失败,请确认图片类型是否正确!')</script>");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ out.println("<script>parent.file_result2('图片上传失败,请确认图片大小是否过大!')</script>");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch(Exception ex) {
|
|
|
+ System.out.println(ex);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ }
|
|
|
+%>
|
|
|
+<!DOCTYPE html>
|
|
|
+<html>
|
|
|
+<head>
|
|
|
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
|
+<title>Insert title here</title>
|
|
|
+</head>
|
|
|
+<body style="background:#002c59;height:120px;width:200px;color:white;">
|
|
|
+</body>
|
|
|
+</html>
|