Solved

File Upload With <INPUT TYPE="FILE"

Posted on 1997-12-16
7
172 Views
Last Modified: 2013-12-25
How do you handle a file being uploaded from the browser's machine with the html form element <INPUT TYPE
0
Comment
Question by:icache
7 Comments
 
LVL 2

Expert Comment

by:haystor
ID: 1831666
Are you prepared to program Perl to do this?
0
 

Author Comment

by:icache
ID: 1831667
Got the Llama book next to me, we're prepared....
0
 
LVL 5

Accepted Solution

by:
icd earned 200 total points
ID: 1831668
First get a copy of the cgi-bin.pl library from

http://cgi-lib.stanford.edu/cgi-lib/

The latest version of this provides for file upload. The above URL will give a description of the program.

Second. You need an input form. This is one I use.

<form method='POST' enctype='multipart/form-data' action='upload.pl'>
<input type="file" name="upfile" size=25>
<INPUT TYPE="image" NAME="submit" value="submit" src="/img/upload.gif" border=0 alt="upload" hspace=2>
</form>

Third. You need to produce your own cgi-script to process the input. The file contents will be in one of the input variables. This is the segment of code I use to save an uploaded file.

require "cgi-bin.pl";
&ReadParse;

if (open (FUPL, ">../files/uploadfilename.tmp")) {
  print FUPL $in{'upfile'};
  close (FUPL);
} else {
  print "<b>$in{filename}</b> upload failed<br>\n";
  return;
}

And that is all there is to it!
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 5

Expert Comment

by:julio011597
ID: 1831669
I'm afraid that works on text files only, doesn't it?
You need some extra processing to handle encoded binary data.
0
 
LVL 5

Expert Comment

by:icd
ID: 1831670
No. It works on binary files as well. (At least I have had no problems so far!).
0
 

Author Comment

by:icache
ID: 1831671
You've stated that the file's contents will be in the the variable of the element $in('file'}. What I'm getting as the content of that element is just the file's name, not the contents. I haven't had a chance to install cgi-bin.pl and give your suggestion a try, but does cgi-bin.pl findthe contents in that element while stdin alone cannot
0
 
LVL 5

Expert Comment

by:icd
ID: 1831672
Actually it should be in $in{'upfile'} since that is the name of the <input type="file" input field.

Are you sure you used the correct 'enctype'?

Interpretation of stdin without cgi-bin.pl can be quite complex. I suggest you load a copy of cgi-bin.pl.

Another possible problem could be that ISTR that Microsoft IE does not support the input type="file". (I have not checked this recently).

0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I do this in Pyhton? 12 137
issue with beginner powershell script. 5 75
Perl script to process a .csv file 18 60
PowerShell logging 1 27
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

762 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