Solved

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

Posted on 2004-09-03
13
187 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:kheefatt
Comment Utility
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
Comment Utility
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
Comment Utility
>  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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
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
Comment Utility
There is really no other other ways in JSP page or HTML?
0
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
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
Comment Utility
>  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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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