Have you looked at the CGI.pm docs?
There are two parts to uploading docs via a webpage. First, you have supply the
correct type of form on the webpage:
is probably the bare minimum that you need.
Then, the script needs to properly parse the sent file. Below is a loop that I
use in a script I have. You should probably customize this to fit your
needs
foreach my $file_type ('resp', 'family', 'cancer') {
# first, we need to grab the uploaded file's file handle, and check
# to see if there was an error during the send
my $fh = $q->upload($file_type);
if (!$fh && $q->cgi_error) {
die("File upload error for $file_type: " . $q->cgi_error);
} elsif (!$fh) {
die("No file specified for $file_type");
}
# here, we make sure that the file name contains the $file_type string.
This
# is used as a simple stop-gap to try and make sure that the correct
file is being
# passed for each parameter...
my $in_file_name = $q->param($file_type);
$in_file_name =~ s/\\/\//g;
{
# the uploaded file's name contains the entire remote path
my $fname = pop @{[ split("/", $in_file_name) ]};
unless ($fname =~ m/$file_type/i) {
die("File uploaded for file type '$file_type' was named
'$fname', which doesn't contain the string '$file_type'");
}
}
# at this point, we have a good file that has been uploaded
open(my $out, ">", $save_dir . $file_type . '.dat') or die("Could not
create '$save_dir$file_type.dat': $!");
# just in case, although on unix boxes it shouldn't matter, we make sure
that
# we have raw character discipline
binmode($fh, ":raw");
binmode($out, ":raw");
# now, read the data using buffered IO (rather than sysread)
my $bytesread;
my $buffer;
while($bytesread = read($fh, $buffer, 1024)) {
print $out $buffer;
}
# read returns undef on an error. I don't know where this error gets
stored...
if (!defined($bytesread)) {
die("An error occured while trying to write '$save_dir$file_type.dat':
$!");
}
# now close the files...
close($fh);
close($out);
}
HTH,
Ricky
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs