用于文件上传的 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
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!
Here is the code:
#!/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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 CanSpice 指出的,这个问题 给出答案:
As CanSpice pointed out, this question gives the answer:
CGI除了大量的文档之外,还附带了很多示例,请参见http://search.cpan .org/dist/CGI/MANIFEST
因此,结合这些知识,您可以编写
当您切换到 Dancer/Catalyst/Mojolicious 时,您的代码会缩小
CGI, besides lots of documentation, also comes with a lot of examples, see http://search.cpan.org/dist/CGI/MANIFEST
So combined with that knowledge, you can write
Your code shrinks when you switch to Dancer/Catalyst/Mojolicious
您可以使用此代码,将正常工作。
You can use this code, will work properly.