Solved

all about <input type=file>

Posted on 1998-07-22
4
129 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 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
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…
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 …

771 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

7 Experts available now in Live!

Get 1:1 Help Now