Why can't I upload file in my this CGI script?

K

Koms Bomb

Environment: Win2000 professional, Apache 2.0, Perl 5.8, CGI.pm
I write and test my script on Win2K but I hope my script will be platform
independent.

The code is,

#!d:/perl/bin/perl.exe
use strict;
use warnings;
use CGI;
use MIME::Lite;
use File::Copy;

[snip]

my $fn = $cgi->param('screenshot'); #here $fn is the path of my client side!
if(defined $fn) {
$fn =~ s/.*[\/\\](.*)/$1/;
my $fh = $cgi->upload('screenshot');
binmode($fh);
copy($fh, './' . $fn);
print $fn;
#attach the file to mail message.
$msg->attach(Type =>'image/gif',
Path =>$fn,
Filename =>'./' . $fn
);
}

'screenshot' is the field name of fileupload, in html,
<td><input type="file" name="screenshot"
enctype='multipart/form-data'></td>.

I saw $fn is my client side file name, eg, if I select e:\temp\x.zip,
$fn is e:\temp\x.zip, not relate to any Apache environment. That is
obviously wrong.
My script works find except I can't upload file.

I've googled sample code for file uploading, but they can't work on my
system too.
I'm not good at Perl, and I don't know whether the error is due to my script
or
due to Apache/Win2K.

Any suggestion or anyone can give some sample code that can work on
Apache/Win2K ?
 
G

Gunnar Hjalmarsson

Koms said:
'screenshot' is the field name of fileupload, in html,
<td><input type="file" name="screenshot"
enctype='multipart/form-data'></td>.

enctype='multipart/form-data'

shall be in the form tag.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top