[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

all about <input type=file>

Posted on 1998-07-22
4
Medium Priority
?
150 Views
Last Modified: 2013-12-25
1. Can I designate the directory or the final desired URL of the file as the URL in the action of the form?
2. If I give the URL of a script as the URL of the form, how does the file look when it gets there? Does it look like the contents of a <textarea>? Can I have several input fields on the one form and each one will get there intact?
0
Comment
Question by:rafistern
[X]
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
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 400 total points
ID: 1831135
You need a CGI - there is no inherent reason except security that a server couldn't support direct upload, but I haven't heard of any. For security reasons you simply couldn't allow the file to be uploaded anywhere where it could be called from the web.

The data is encoded in the special multipart/form-data MIME format, where boundary separators are used to delimit the fields. (Boundaries are chosen randomly by the browser to be text that won't appear in the file).

The following form:

<FORM NAME="upload" ACTION="upload.pl" METHOD=POST enctype="multipart/form-data">
Choose file: <INPUT TYPE=file NAME=filename> <br>
Description: <INPUT TYPE=text NAME=description>
<INPUT TYPE="SUBMIT" VALUE="Send File">
</form>

Produces the following input to the script:
Content-type: multipart/form-data; boundary=---------------------------259473011527166
Content-Length: 328

-----------------------------259473011527166
Content-Disposition: form-data; name="filename"; filename="d:\wwwtest\test"

this is a test upload file

-----------------------------259473011527166
Content-Disposition: form-data; name="description"

This is the description
-----------------------------259473011527166--

Hope this helps!
0
 
LVL 6

Expert Comment

by:alamo
ID: 1831136
One minor correction -

I posted in the answer that the input your script received included the Content-type and Content-Length. Something was nagging at me, and I just figured out what: those two values are passed to you in the environment, not in the input stream.

So the first line in the input stream would be:
-----------------------------248212550332709

and the environment would have:
CONTENT_LENGTH=309
CONTENT_TYPE=multipart/form-data; boundary=---------------------------248212550332709
HTTP_CONTENT_LENGTH=309
HTTP_CONTENT_TYPE=multipart/form-data; boundary=---------------------------248212550332709

Sorry for the mistake!
0
 
LVL 4

Author Comment

by:rafistern
ID: 1831137
Sorry for the delay in responding but the email notification seems to have gone astray. From what I understand, I get the input you gave me above in stdin of the script. What I have to do is strip away the boundaries and all the garbage and there I have the file. Correct?

Does this apply to a binary file as well?

Could I use a procedure like &ReadParse to get the file contents as $in{"filename"} using your example?

Would this work for a binary file?
0
 
LVL 6

Expert Comment

by:alamo
ID: 1831138
Yes, upload works for a binary file - the data in each field is the direct binary data not an encoded version.

If by ReadParse you mean cgi-lin.pl's ReadParse, the answer is yes, I don't use it but I have read that version 2.17 of cgi-lib.pl supports multipart-mixed encoding for file uploads. I think it saves the file itself to disk (needed in case it's very large) and places the rest of the fields into the normal $in{} hash. (My info on this came from http://cgi-lib.stanford.edu/cgi-lib/).
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Suggested Courses

656 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