Perl的CGI.pm可以处理Firefox的<input type ="file",multiple ="">表单字段吗?

pd_*_*_au 4 perl firefox file input

Firefox 3.6引入了[常规类型="文件"输入元素的多个属性]( http://hacks.mozilla.org/2009/12/multiple-file-input-in-firefox-3-6/).

我不能让Perl处理这些字段.我可以在列表上下文中调用该字段,如下所示:

 my @files = $CGIobject->param("File_Input");
Run Code Online (Sandbox Code Playgroud)

通过它循环将给我文件名作为字符串,但没有别的.

任何建议都会受到欢迎.

这是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>
Run Code Online (Sandbox Code Playgroud)

这是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;

  }

}
Run Code Online (Sandbox Code Playgroud)

该脚本不会进入

if (@lightweight_fh) {
Run Code Online (Sandbox Code Playgroud)

块.

我在if块之前尝试了数据:@lightweight_fh上的Dumper,它确实打印出来并没有任何内容.

dax*_*xim 6

使用CGI.pm中upload方法.

在列表上下文中,upload()将返回文件句柄数组.这使得处理多个上载字段使用相同名称的表单成为可能.


pd_*_*_au 5

哇哇,得到了这个工作.大手刹问题?旧CGI.pm版!令人遗憾的是,CGI.pm文档中不包含诸如"在X版本中引入"等功能的注释.许多其他模块/库/包都可以.

碰巧我有3.15版本,目前是3.49.我甚至让它以严格的模式工作.有谁知道斯坦因为什么使用非严格的例子?

这是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>
Run Code Online (Sandbox Code Playgroud)

这是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

      }

    }

  }
Run Code Online (Sandbox Code Playgroud)

谢谢大家的帮助.