用于文件上载的Perl脚本

我试图在Perl中编写一个允许用户上传文件的脚本.目前,它说它正在工作,但实际上并没有上传文件

这是代码

#!/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';
 while(<$file>) {
    print LOCAL $_;
 }
 print $cgi->header();
 print $dir/$name;
 print "$file has been successfully uploaded... thank you.\n";enter code here

解决方法

正如CanSpice指出的那样,this question给出了答案:
#!/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

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...