尝试使用Plack处理多个文件上传.
我的表格:@H_403_3@
<form id="file_upload" action="savefile" method="POST" enctype="multipart/form-data"> <input type="file" name="file[]" multiple> <button>upload</button> </form>
选择了两个文件,名为:x1和x2. Data :: Dumper结果如下:@H_403_3@
my $u = $req->uploads;
是@H_403_3@
$VAR1 = bless( { 'file[]' => bless( { 'headers' => bless( { 'content-disposition' => 'form-data; name="file[]"; filename="x2"','content-type' => 'application/octet-stream','::std_case' => { 'content-disposition' => 'Content-Disposition' } },'HTTP::Headers' ),'filename' => 'x2','tempname' => '/var/folders/7l/nhyscwy14bjb_sxr_t2gynpm0000gn/T/7vt04wIrne','size' => 146 },'Plack::Request::Upload' ) },'Hash::MultiValue' );
因此,它只包含第二个文件x2,但是当选中文件夹/ var / folders / 7l / nhyscwy14bjb_sxr_t2gynpm0000gn / T /它包含上传的两个文件.@H_403_3@
解决方法
for my $upload ($req->upload('file[]')) { $upload->filename; }
您也可以调用@uploads = $req-> uploads-> get_all(‘file []’)来获取多个值.@H_403_3@
有关详细信息,请参见perldoc Plack::Request
(和Hash::MultiValue
).@H_403_3@
你在Data :: Dumper中没有看到它们的原因是Hash :: MultiValue使用一种称为inside-out对象的技术来保存给定键的替代值.@H_403_3@