尝试用Plack处理多个文件上传。
我的表格:
<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结果:
my $u = $req->uploads;是
$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/时,它包含上传的两个文件。
问题是我怎样才能把两个文件都拿到脚本,而不是最后一个呢?
发布于 2013-08-10 21:14:15
for my $upload ($req->upload('file[]')) {
$upload->filename;
}您还可以调用@uploads = $req->uploads->get_all('file[]')来获取多个值。
有关更多细节,请参见perldoc Plack::Request (和Hash::MultiValue)。
您没有在Data::Dumper中看到它们的原因是Hash::MultiValue使用了一种名为inside-out对象的技术来为给定的键保存备用值。
https://stackoverflow.com/questions/18166156
复制相似问题