Perl的CGI.pm可以处理Firefox的< input type =" file" multiple ="">表单域? [英] Can Perl's CGI.pm process Firefox's <input type="file", multiple=""> form fields?
问题描述
http://hacks.mozilla.org/2009/12/multiple-file-input-in-firefox-3-6/ )。
我无法让Perl处理这些字段。我可以在这样的列表上下文中调用这个字段:
$ p $ my $ files = $ CGIobject-> param(File_Input );
循环读取文件名将会以字符串形式给出,而不是别的。
$ b
任何建议都会受到欢迎。
以下是HTML:
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Strict // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict .dtd>
< html>
< head>
< title>多个文件上传测试< / title>
< / head>
< body>
< form action =deliberately_obfuscated
method =post
enctype =multipart / form-data>
< input type =file
name =multiple_files
multiple =true/>
< button type =submit>提交< / button>
< / form>
< / body>
< / html>
这是Perl:
<$ p $ <!c $ c>#!/ usr / bin / perl
#use strict;
#使用警告;
使用CGI;
my $ CGIo =新的CGI;
print $ CGIo-> header();
@lightweight_fh = $ CGIo-> upload('myfiles');
#undef可能被返回
#如果它不是
#有效的文件句柄
if(@lightweight_fh){
#将句柄升级到
#一个兼容IO :: Handle:
my $ io_handle = $ lightweight_fh->句柄;
open(OUTFILE,>>','/ hidden_deliberately /');
$ b $ while($ bytesread = $ io_handle-> read($ buffer,1024)){
print OUTFILE $ buffer;
$ b $ $
$ b
如果(@lightweight_fh){
不输入
>
块。
我试过了在if区块之前的@lightweight_fh上的Data:Dumper,它实际上完全没有打印任何东西。
解决方案
呜呼,得到了这个工作。大手刹问题?旧的CGI.pm版本! CGI.pm文档中不包含与X版本中介绍的功能相关的注释。许多其他模块/库/软件包。
碰巧我的版本是3.15,当前是3.49。我甚至在严格的模式下工作。有人知道为什么Stein使用非严格的示例吗?
这里是XHTML:
pre $ code><!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Strict // EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd >
< html>
< head>
< title>多个文件上传测试< / title>
< / head>
< body>
这里是Perl:
#!/ usr / bin / perl
use strict;
使用警告;
使用CGI;
my $ CGIo =新的CGI;
print $ CGIo-> header();
我的@lightweight_fh = $ CGIo->上传('multiple_files');
foreach如果不是有效的文件句柄
if(defined $ fh ){
#将句柄升级到与IO :: Handle兼容的句柄:
$ b $ my $ io_handle = $ fh->句柄;
open(OUTFILE,'>>','/ deliberately_hidden /'。$ fh);
$ b $ while(my $ bytesread = $ io_handle-> read(my $ buffer,1024)){
print OUTFILE $ buffer
}
$ b code
$ b 感谢您的帮助每个人。
Firefox 3.6 introduced a [multiple attribute on regular type="file" input elements](
http://hacks.mozilla.org/2009/12/multiple-file-input-in-firefox-3-6/).
I cannot get Perl to process these fields. I can call the field in a list context like this:
my @files = $CGIobject->param("File_Input");
Looping through that will give me the file names as strings but nothing else.
Any suggestions would be greatly welcome.
Here's the 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>
Here is the 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;
}
}
The script does not enter the
if (@lightweight_fh) {
block.
I've tried Data:Dumper on @lightweight_fh before the if block and it literally prints absolutely nothing.
解决方案 Woohoo, got this working. The big handbrake issue? Old CGI.pm version! It's a shame the CGI.pm documentation does not include notes alongside features such as "Introduced in version X". Many other modules/libraries/packages do.
As it happens I had version 3.15 and the current is 3.49. I even got it working in strict mode. Anybody know why Stein uses non-strict examples?
Here's the XHTML:
<!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_hidden"
method="post"
enctype="multipart/form-data">
<input type="file"
name="multiple_files"
multiple="true"/>
<button type="submit">Submit</button>
</form>
</body>
</html>
Here's the Perl:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $CGIo = new CGI;
print $CGIo->header();
my @lightweight_fh = $CGIo->upload('multiple_files');
foreach my $fh (@lightweight_fh) {
# undef may be returned if it's not a valid file handle
if (defined $fh) {
# Upgrade the handle to one compatible with IO::Handle:
my $io_handle = $fh->handle;
open (OUTFILE,'>>','/deliberately_hidden/' . $fh);
while (my $bytesread = $io_handle->read(my $buffer,1024)) {
print OUTFILE $buffer
}
}
}
Thanks for your help everyone.
这篇关于Perl的CGI.pm可以处理Firefox的< input type =" file" multiple ="">表单域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!