[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

File Upload With <INPUT TYPE="FILE"

How do you handle a file being uploaded from the browser's machine with the html form element <INPUT TYPE
1 Solution
Are you prepared to program Perl to do this?
icacheAuthor Commented:
Got the Llama book next to me, we're prepared....
First get a copy of the cgi-bin.pl library from


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>

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";

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

And that is all there is to it!
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

I'm afraid that works on text files only, doesn't it?
You need some extra processing to handle encoded binary data.
No. It works on binary files as well. (At least I have had no problems so far!).
icacheAuthor Commented:
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
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).


Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now