Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Uploading files with input type="text" in form instead of input type="file"

Posted on 2004-09-03
13
190 Views
Last Modified: 2008-02-01
I have a upload form and it is working fine with the input type="file". However, when I try to change it to textbox (input type="text") or "hidden", it won't work anymore. I think this is because "file" input type have some properties which "text" doesnt have and causes the uploadBean not working properly. However, I'm retrieving the link from database instead of user browsing it for this uploading function. And with input type="file", I couldnt assign any values into it, even though I declare value="c:\abc\abc.zip" in input properties...it also didnt appear any values although I assign some values through jsp or even javascript. Any help is much appreciated or even any alternatives way to solve my problem. Thank you in advance.

0
Comment
Question by:kheefatt
  • 5
  • 4
  • 3
13 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 11971099
When the input type is of type 'file', the actual file will be uploaded when the form is submited.  When the type is 'text', just the filename is uploaded.

I don't think it is possible to programatically set an file input element.  This would be a security violation because you are taking the users choice to upload the file away from him.  This means that you could for example upload dangerous or personal files without the user's concent.  For example how would you like it if a page automatically uploaded your Microsoft Money file(which contains your credit card information).
0
 
LVL 35

Accepted Solution

by:
TimYates earned 125 total points
ID: 11971101
You have to use FILE for uploading files unfortunately (for security reasons)...

Can you explain a bit more?  When you say you are getting the file from a database, does that mean you already know what file it is?  Or are you trying to limit the files the user can select?

One way of getting round this MAY be to use a signed applet to show a file dialog, and post the file to the server in a multipart post request (as usually happens with FILE)

Tim
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 11971158
On the plus side, you can achieve the same functionality by using the XMLHTTP obect.  This is only feasable if you are running in localhost or intranet, because it involves changing the user's security zone settings.  See the following links (You will have to implement the corresponding server stuff in JSP instead of ASP):

http://www.15seconds.com/issue/010522.htm
http://builder.com.com/5100-31-5078105.html
http://www.experts-exchange.com/Web/Web_Languages/Q_20639591.html
http://rtfm.atrax.co.uk/infinitemonkeys/articles/asp/933.asp
http://www.uonbi.ac.ke/acad_depts/ics/course_material/javascripts/uploading_files_with_XMLHTTP.htm
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:kheefatt
ID: 11971325
I'm implementing a drag and drop application where there are two frames available. On the left frame, it will show all the local directory and files on the user's pc. And on the right frame, there is a content tree (in tree structure format build from database) which contains a few categories.

When user drag a particular file and drop into a specific category, a pop up window will appear. This pop up window is used as form submission for user to key in the information and properties of the file. When the form is completed, this pop up window will close and the information is saved into the database. The path of this file will be saved in a different table which is called UploadContent.

So when the pop up window is close, user will go back to the tree structure frame and there is upload button there. When the button is clicked, it will get the link from UploadContent and the file is uploaded to the server. After uploading, the path will be deleted from the database, the tree is automatically refresh and the file will be included into the tree as well.

I tried few ways of integrating it with the upload function i have. All the examples I have is getting the path from file control. Is there any other ways where I can straight get the pathname from database and do the uploading using the available link?
 
0
 

Author Comment

by:kheefatt
ID: 11971392
MogalManic,

The site builder.com that u have can solve my problem. However it is in ASP. Do u have any written using JSP?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11971509
>  On the plus side, you can achieve the same functionality by using the XMLHTTP obect

Does that work on any OS other than Windows?  And any browser other than IE?  All of the examples of XMLHTTP I've seen have never worked for me on Linux with FireFox...
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 11971705
Tim,
You are right, the XMLHTTP object works only using IE and probably only on Windows.  If kheefat is creating an Internet application where the client box cannot be controlled, then most portable solution would be to use a Java Applet which posts the file using the URLConnection class
0
 

Author Comment

by:kheefatt
ID: 11971753
There is really no other other ways in JSP page or HTML?
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 11971767
kheefat,

To answer your question, you should be able to use the same upload bean that you are currently using.  Or try this:
http://www.devsphere.com/mapping/docs/guide/upload.html


You also probably need to do this on the client before sending:
  objXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11972003
>  There is really no other other ways in JSP page or HTML?

If you are sure all the users of your application will be using IE on Windows, then MogalManic's method should work...

If you can't...there is no other way of doing it, apart from using the FILE tag
0
 

Author Comment

by:kheefatt
ID: 11987061
If I have the filepath, is it possible to assign it to a textbox then call an upload function to upload a file from there?
0
 

Author Comment

by:kheefatt
ID: 11988299
http://www.devsphere.com/mapping/docs/guide/upload.html is missing the class FileBean. U guys know where can get it? If u have, can u please just paste the codes here. Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question