<FORM METHOD="POST" ACTION="script.pl" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" SIZE="30" NAME="UPLOAD" ACCEPT="text/plain,image/gif">
</FORM>
You have to use the multipart/form-data enctype on the form.
I'm not sure if that ACCEPT thing works since I haven't had too much luck with it myself, but I saw it in the docs. It's supposed to prevent the uploading of unwanted types.
Anyway, using cgi-lib.pl or the CGI_Lite module:
# get the file from the input stream
$upload = $in{"UPLOAD"};
# check if it's there, and write it to disk
if ($upload)
{
# if it's a gif
if ($upload=~/GIF/)
{
open (IMAGE, ">filename.gif"

|| die "$!";
binmode(IMAGE);
unless (flock (IMAGE, LOCK_EX)) {die "$!"}
print IMAGE $upload;
close(IMAGE);
}
# if it's plain text
else
{
open (TEXT, ">filename.txt"

|| die "$!";
unless (flock (TEXT, LOCK_EX)) {die "$!"}
print TEXT $upload;
close(TEXT);
}
}
This, of course, assumes that you are only accepting gifs or plain text. You can actually upload any filetype you want. You have to figure out how to determine it's type though. For instance, gifs have "GIF" in their header. You also have to figure out how to name the file, either by a common system or let the user determine a name (potentially dangerous). You don't have to save the file either... you could print it to the screen. It's just a string containing the file contents, so you could print plain text directly, or you could put an image into the src of an image tag. Or you could perform computations and alterations to it before printing or saving it.
I hope this answers your question.
Sincerely,
Tom Anderson
CEO, Order amid Chaos, Inc.