Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Why can't I upload file in my this CGI script?

Reply
Thread Tools

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

 
 
Koms Bomb
Guest
Posts: n/a
 
      07-01-2004
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 ?


--
Koms Bomb

*****Pardon my poor English*****
---------------------
My TASM homepage, resource for assembly. Tools, articles, links.
http://komsbomb.ols-lab.com



 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-01-2004
Koms Bomb wrote:
>
> '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.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Koms Bomb
Guest
Posts: n/a
 
      07-02-2004
> enctype='multipart/form-data'
>
> shall be in the form tag.


Thank your very much, it works.
Seems I should learn more HTML syntax.


--
Koms Bomb

*****Pardon my poor English*****
---------------------
My TASM homepage, resource for assembly. Tools, articles, links.
http://komsbomb.ols-lab.com


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
CGI file upload - problems with file size... DJ Stunks Perl Misc 1 01-23-2006 05:35 PM
Upload a file without file Upload control - ASP.Net =?Utf-8?B?U2FyYXY=?= ASP .Net 3 08-03-2005 01:09 AM
How to detect sizeof upload in order to show status of browser file upload? Heather Fraser Java 0 07-05-2004 12:35 AM



Advertisments