I'm trying to convert a piece of code that I got working on Windows, but I am unable to convert for Linux. I'm trying to upload an image using <input type="file" name="filename" size="50">
The following is the submitting page(upload.jsp) which attempts to upload the file located from the previous page, written exactly as it is for my Windows server.
--------------------------------------------------------
<%@ page import="java.util.*,java.io.*"%>
<%
String path=request.getParameter("filename");
String newPath="";
int count=0;
if(path!=null)
{
ArrayList arr=new ArrayList();
StringTokenizer st=new StringTokenizer(path,"\\");
while(st.hasMoreTokens())
{
arr.add(count,st.nextToken());
count++;
}
// create ur own path
newPath="C:\\Tomcat5\\webapps\\meetings\\xmasxonference\\upload\\"+arr.get(count-1);
int c;
FileInputStream fis=new FileInputStream(path);
FileOutputStream fos=new FileOutputStream(newPath);
while((c=fis.read())!=-1)
{
fos.write((char)c);
}
}
out.println("Thanks for using");
out.println("<br>");
out.println("<br>");
out.println("1.File1 Uploaded from :: "+path);
out.println("<br>");
out.println("<br>");
out.println("2.Uploaded File1 is Saved in :: "+newPath);
%>
--------------------------------------------
I've tried setting the following
newPath = /home/tomcat/jakarta-tomcat-5.0.18/webapps/meetings/xmas/images/"+arr.get(count-1);
and changing the tokenizer, as well as using
String appPath = application.getRealPath("/");
to get a relative path, which is preferable but with no success.
Any pointers, anyone? TIA dubya
The following is the submitting page(upload.jsp) which attempts to upload the file located from the previous page, written exactly as it is for my Windows server.
--------------------------------------------------------
<%@ page import="java.util.*,java.io.*"%>
<%
String path=request.getParameter("filename");
String newPath="";
int count=0;
if(path!=null)
{
ArrayList arr=new ArrayList();
StringTokenizer st=new StringTokenizer(path,"\\");
while(st.hasMoreTokens())
{
arr.add(count,st.nextToken());
count++;
}
// create ur own path
newPath="C:\\Tomcat5\\webapps\\meetings\\xmasxonference\\upload\\"+arr.get(count-1);
int c;
FileInputStream fis=new FileInputStream(path);
FileOutputStream fos=new FileOutputStream(newPath);
while((c=fis.read())!=-1)
{
fos.write((char)c);
}
}
out.println("Thanks for using");
out.println("<br>");
out.println("<br>");
out.println("1.File1 Uploaded from :: "+path);
out.println("<br>");
out.println("<br>");
out.println("2.Uploaded File1 is Saved in :: "+newPath);
%>
--------------------------------------------
I've tried setting the following
newPath = /home/tomcat/jakarta-tomcat-5.0.18/webapps/meetings/xmas/images/"+arr.get(count-1);
and changing the tokenizer, as well as using
String appPath = application.getRealPath("/");
to get a relative path, which is preferable but with no success.
Any pointers, anyone? TIA dubya