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