Solved

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

Posted on 2004-09-03
13
189 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Read about the ways of improving workplace communication.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now