In my program I am trying to have a user upload a file
to an apache web server. but my current code does not
upload anything. Help please.
use strict;
use CGI qw(:standard);
print header(),start_html('Upload Files');
print start_multipart_form();
print h2('Upload Files');
print "Select the File: ",
filefield(-name=>'filepath',
-size=>30,
-maxlength=>100),
p,
reset, submit('submit', 'Upload File');
print end_form();
if (my $filehandle = param('filepath')) {
doUpload();
}
else {
print "Choose a file to upload";
}
sub doUpload {
my ($bytes, $buffer, $bytesread);
my $filehandle = CGI::param('filepath');
open OUTFILE, '>$filehandle' or die "Couldn't open output file: $!\n";
while ($bytes = read($filehandle, $buffer, 1024)){
$bytesread += $bytes;
print OUTFILE $buffer;
}
warn "Recieved $bytesread bytes";
close OUTFILE;
}
print end_html;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.