Solved

Uploading files via a HTML Form

Posted on 1998-10-20
1
156 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

16 Experts available now in Live!

Get 1:1 Help Now