Solved

all about <input type=file>

Posted on 1998-07-22
4
140 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 100 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

732 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