File Upload With <INPUT TYPE="FILE"

Posted on 1997-12-16
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
Question by:icache
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

Expert Comment

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

Author Comment

ID: 1831667
Got the Llama book next to me, we're prepared....

Accepted Solution

icd earned 200 total points
ID: 1831668
First get a copy of the 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=''>
<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 "";

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!
AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.


Expert Comment

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

Expert Comment

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

Author Comment

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 and give your suggestion a try, but does findthe contents in that element while stdin alone cannot

Expert Comment

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 can be quite complex. I suggest you load a copy of

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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

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…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
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…
The viewer will learn how to dynamically set the form action using jQuery.

615 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