Solved

Uploading files via a HTML Form

Posted on 1998-10-20
1
171 Views
Last Modified: 2010-03-05
How do I create a perl script that will allow somebody to attatch a file to a HTML form.

The file, along with other text inputs, will always be stored in the same directory with the same file name.

I am familar with perl, cgi scripting, file creation etc.
All I need is a pointer on how this can be done.

i would imagine that somehow a data stream is opened, and I could then take this (binary?) data and save it to a file?

how does the HTML form send the data?

thanks.
0
Comment
Question by:blacksheep
1 Comment
 
LVL 28

Accepted Solution

by:
sybe earned 130 total points
ID: 1205537
Make a form like this:

============
<FORM ACTION="/cgi-bin/upload.pl" ENCTYPE="MULTIPART/FORM-DATA" METHOD="POST">
<INPUT TYPE="FILE" NAME="FILE1">
</FORM>
===========

code for upload.pl

===========

require "./cgi-lib.pl";

$cgi_lib'maxdata = 50000;

$ret = &ReadParse;

open(OUTFILE, ">upload/test.gif");
binmode (OUTFILE);
syswrite (OUTFILE, $in{'upfile'}, length $in{'upfile'});
close(OUTFILE);


print &PrintHeader;

print "\n<P>File was uploaded<P>";

print &HtmlBot;

===============
It uses cgi-lib.pl, which you can get from http://www.bio.cam.ac.uk/cgi-lib/



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

864 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now