用于文件上传的Perl脚本 [英] Perl script for file upload
本文介绍了用于文件上传的Perl脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Perl中编写一个脚本,该脚本将允许用户上传文件。目前,它说它正在运行,但实际上并没有上传文件!
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!
这里是代码:
#!/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指出的那样,此问题给出了答案:
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
这篇关于用于文件上传的Perl脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文