Perl script for file upload

前端 未结 3 1515
死守一世寂寞
死守一世寂寞 2021-01-21 14:48

I am trying to write a script in Perl that will allow the user to upload a file. At the moment, it says that it is working, but it does not actually upload the file!

Her

3条回答
  •  一个人的身影
    2021-01-21 15:23

    As CanSpice pointed out, this question gives the answer:

     #!/usr/bin/perl
     use CGI;
     my $cgi = new CGI;
     my $dir = 'sub';
     my $file = $cgi->param('file');
     $file=~m/^.*(\\|\/)(.*)/;
     # strip the remote path and keep the filename
     my $name = $2;
     open(LOCAL, ">$dir/$name") or print 'error';
     my $file_handle = $cgi->upload('file');     // get the handle, not just the filename
     while(<$file_handle>) {               // use that handle
        print LOCAL $_;
     }
     close($file_handle);                        // clean the mess
     close(LOCAL);                               // 
     print $cgi->header();
     print $dir/$name;
     print "$file has been successfully uploaded... thank you.\n";enter code here
    

提交回复
热议问题