?
Solved

all about <input type=file>

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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
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…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

801 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