Hello,
I'm working with a Java Applet called "JUpload", from Source Forge. It is used to upload multiple files through HTTP (the same way that an <input type="file"...> would do with only one file).
The problem is: it use .jsp on the server to process the information send. I belive it's possible to make a PHP script to make the same work, but... i'm becoming crazy,
Some help?
The JSP codes:
parserUpload.jsp
<%@ page language="java" import="java.io.*, java.sql.*, java.util.*, com.oreilly.servlet.MultipartRequest" %>
<%
response.setContentType("text/plain");
try{
String dirName = "c:\\temp\\";
MultipartRequest multi = new MultipartRequest(request, dirName, 10*1024*1024); // 10MB
out.println("Params:");
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements()) {
String name = (String)params.nextElement();
String value = multi.getParameter(name);
out.println(name + " = " + value);
}
out.println();
out.println("Files:");
Enumeration files = multi.getFileNames();
while (files.hasMoreElements()) {
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
String type = multi.getContentType(name);
File f = multi.getFile(name);
out.println("name: " + name);
out.println("filename: " + filename);
out.println("type: " + type);
if (f != null) {
out.println("f.toString(): " + f.toString());
out.println("f.getName(): " + f.getName());
out.println("f.exists(): " + f.exists());
out.println("f.length(): " + f.length());
out.println();
}
}
}catch(Exception e){
out.println("Exception e = " + e.toString());
}
%>
writeOut.jsp
<%@ page language="java" import="java.io.*, java.sql.*, java.util.*" %>
<%
// This JSP will save the request Input Steam into a file.
String fileOut = "c:/temp/writeOut.bin";
try{
ServletInputStream in = request.getInputStream();
byte[] line = new byte[1024];
int bytes = 0;
FileOutputStream fileOutS = new FileOutputStream(fileOut);
while(0 <(bytes = in.read(line))){
fileOutS.write(line,0, bytes);
}
fileOutS.close();
fileOutS = null;
out.println("SUCCESSFUL : Upload Stream Saved to \"" + fileOut + "\".");
}catch(Exception e){
out.println("ERROR : Exception \"" + e.getMessage() + "\" Occured.");
}
%>
Thank you in advance!!!