用于文件上载的Perl脚本
发布时间:2020-12-15 21:32:59 所属栏目:大数据 来源:网络整理
导读:我试图在Perl中编写一个允许用户上传文件的脚本.目前,它说它正在工作,但实际上并没有上传文件! 这是代码: #!/usr/bin/perl use CGI; my $cgi = new CGI; my $dir = 'sub'; my $file = $cgi-param('file'); $file=~m/^.*(|/)(.*)/; # strip the remote p
我试图在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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |