[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

all about <input type=file>

Posted on 1998-07-22
4
Medium Priority
?
153 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
  • 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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 make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

873 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