66 lines
2.3 KiB
Plaintext
66 lines
2.3 KiB
Plaintext
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
|
|
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
|
|
<%@ page import="org.apache.commons.fileupload.*"%>
|
|
<%@ page import="java.util.Iterator" %>
|
|
<%@ page import="java.util.List" %>
|
|
<%@ page import="java.io.File" %>
|
|
|
|
<%
|
|
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
|
|
String dirPath = getServletContext().getRealPath("/").replace('\\', '/') +
|
|
"data/";
|
|
String itemName;
|
|
File file;
|
|
|
|
|
|
out.println(
|
|
"<!DOCTYPE html>"
|
|
+ "<html><head>"
|
|
+ "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"
|
|
+ "<title>Results</title>"
|
|
+ "<link type=\"text/css\" rel=\"stylesheet\" href=\"resources/main.css\">"
|
|
+ "</head> <body>"
|
|
);
|
|
|
|
// Save file if present
|
|
if (isMultipart) {
|
|
FileItemFactory factory = new DiskFileItemFactory();
|
|
ServletFileUpload upload = new ServletFileUpload(factory);
|
|
List list = null;
|
|
|
|
try { list = upload.parseRequest(request);
|
|
} catch (FileUploadException e) { out.println(e); }
|
|
|
|
Iterator itr = list.iterator();
|
|
while (itr.hasNext()) {
|
|
FileItem item = (FileItem) itr.next();
|
|
if (!item.isFormField()) {
|
|
try {
|
|
itemName = item.getName();
|
|
file = new File(dirPath + itemName);
|
|
item.write(file);
|
|
} catch (Exception e) { }
|
|
}
|
|
}
|
|
} else {
|
|
out.println("<h2 class=\"error\">Not multi-part transmitted...</h2>");
|
|
}
|
|
|
|
// List directory
|
|
File curentDir = new File(dirPath);
|
|
String[] list = curentDir.list();
|
|
for (int i=0; i<list.length; i++) {
|
|
String name = list[i].toLowerCase();
|
|
if (name.contains(".png") || name.contains(".jpg")||
|
|
name.contains(".gif") || name.contains(".jpeg")) {
|
|
out.print("<div class='file'>" +
|
|
"<img class='thumbnail' src='data/" + list[i] +
|
|
"'/></div>");
|
|
} else {
|
|
out.print("<a href='data/" + list[i] + "'/><div class='file'>" + list[i] + "</div></a>");
|
|
}
|
|
}
|
|
|
|
out.println("</body></html>");
|
|
%>
|