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

Discussion in 'Perl Misc' started by Koms Bomb, Jul 1, 2004.

  1. Koms Bomb

    Koms Bomb Guest

    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
    Koms Bomb, Jul 1, 2004
    #1
    1. Advertising

  2. 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
    Gunnar Hjalmarsson, Jul 1, 2004
    #2
    1. Advertising

  3. Koms Bomb

    Koms Bomb Guest

    > 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
    Koms Bomb, Jul 2, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jorch
    Replies:
    2
    Views:
    1,242
    Jorch
    May 18, 2004
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,769
    Smokey Grindel
    Dec 2, 2006
  3. Muzammil
    Replies:
    1
    Views:
    1,074
    red floyd
    Aug 28, 2008
  4. Avin Patel
    Replies:
    4
    Views:
    927
    Brian McCauley
    Nov 5, 2004
  5. kath
    Replies:
    4
    Views:
    539
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page