the problem with "input type = file"
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jie_huang
Posted On:   Monday, February 17, 2003 10:44 AM

In a html page, I wrote:

Please select the file to upload:


Then in the action JSP page, I wrote:

This is the file to be uploaded: out.println(request.getParameter(the_file_path));


This way, the file path together with file name will be displayed. How to display just the file name without directory? How to display just the file type?


If I use this way to upload a file such as /user/file1.doc, will the JSP read this file as coming within the server machine or from the client machine? Apparently, I want the latter.

Re: the problem with "input type = file"

Posted By:   Narayana_murthy  
Posted On:   Tuesday, February 18, 2003 08:26 PM


hi Jie,
Regarding your statement "If I use this way to upload a
file such as /user/file1.doc, will the JSP read this file
as coming within the server machine or from the client
machine? Apparently, I want the latter."

i will try to explaing this as i had experienced i my
earlier attempts:
If you are using ENCTYPE="multipart/form-data" in your form,
and in your action page if you are using the Multipart to
get the file content. the file will be read from the
client machine. now the multipart creates a temperory file
in your temp folder with a different name. So i suggest
you to get the file name with the earlier reply i sent you
then use multipart to get the file content and create a new
file on the server with the actual name and copy the
content.

This above mentioned solution is my experience and it might
not be the same elsewhere. you can give it a shot though.

Murthy

Re: the problem with "input type = file"

Posted By:   Narayana_murthy  
Posted On:   Monday, February 17, 2003 10:11 PM


Make a file object out of the path and then call the function to get the name.

e.g.
suppose the path of the file that is to be uploaded is :
E:\My Documents\Documents\Reademe.doc

make a file object:
File file = new File(E:\My Documents\Documents\Reademe.doc);
String strFileName = file.getName();

Murthy

Re: the problem with "input type = file"

Posted By:   Sujatha_Gopal  
Posted On:   Monday, February 17, 2003 10:00 PM

To display only the file name





<%
int len;
int pos;
String str;

str= request.getParameter("the_file_path");
len=str.length();
pos = str.lastIndexOf('\\');

out.print(str.substring(pos+1,len));
%>

Re: the problem with "input type = file"

Posted By:   Sujatha_Gopal  
Posted On:   Monday, February 17, 2003 08:32 PM

To display the file type



<%
int len=0;
len = request.getParameter("the_file_path").length();
out.print(request.getParameter("the_file_path").substring(len-3,len));
%>
About | Sitemap | Contact