Firefox 3.6引入了[常规类型=“文件”输入元素的多重属性]( http://hacks.mozilla.org/2009/12/multiple-file-input-in-firefox-3-6/)。Perl的CGI.pm能处理Firefox的<input type =“file”,multiple =“”>表单字段吗?
我无法让Perl来处理这些字段。我可以在这样的列表环境中调用该字段:
my @files = $CGIobject->param("File_Input");
通过循环,将给我的文件名称作为字符串,但没有别的。
任何建议将非常欢迎。
这里的HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Multiple file upload test</title>
</head>
<body>
<form action="deliberately_obfuscated"
method="post"
enctype="multipart/form-data">
<input type="file"
name="multiple_files"
multiple="true"/>
<button type="submit">Submit</button>
</form>
</body>
</html>
这里是Perl:
#!/usr/bin/perl
#use strict;
#use warnings;
use CGI;
my $CGIo = new CGI;
print $CGIo->header();
@lightweight_fh = $CGIo->upload('myfiles');
# undef may be returned
# if it's not a
# valid file handle
if (@lightweight_fh) {
# Upgrade the handle to
# one compatible with IO::Handle:
my $io_handle = $lightweight_fh->handle;
open (OUTFILE,'>>','/hidden_deliberately/');
while ($bytesread = $io_handle->read($buffer,1024)){
print OUTFILE $buffer;
}
}
脚本不会进入
if (@lightweight_fh) {
块。
我试过数据:在iflight块之前的@lightweight_fh上的Dumper,它从字面上完全没有打印任何东西。
多文件输入将为您提供一个字段数组,其中只有一个字段。我不会说Perl,所以我不知道如何改变语法,但它应该非常简单。 – 2010-08-10 10:51:20
始终发布完整的示例脚本,以便我们可以看到您所做的一切。 – 2010-08-10 12:16:00