简体   繁体   English

如何使用Apache2 :: Upload在表单提交中处理多个文件?

[英]How do you handle multiple files in a form submission using Apache2::Upload?

I'm writing a small web application using Perl, HTML::Mason and Apache. 我正在使用Perl, HTML::Mason和Apache编写一个小型Web应用程序。

I've been using Mason's usual <%args> method for receiving 'normal' form parameters, and Apache2::Upload for receiving files. 我一直在使用Mason通常的<%args>方法来接收'普通'表单参数,并使用Apache2::Upload来接收文件。

However, I want to write a page that allows a user to upload multiple files, and I'd like to take advantage of HTML5's multiple attribute to input fields. 但是,我想写一个允许用户上传多个文件的页面,我想利用HTML5的multiple属性来输入字段。 This will look to the server as though there were multiple file inputs in the form with the same name. 这将使服务器看起来好像在表单中有多个具有相同名称的文件输入。

The interface for Apache2::Upload doesn't seem to directly support this, allowing you instead to just get the data for a file with a particular parameter name. Apache2::Upload的界面似乎不直接支持这一点,允许您只获取具有特定参数名称的文件的数据。 The documentation alludes to using APR::Request::Param::Table , but I can't find any documentation for doing that. 文档暗示使用APR::Request::Param::Table ,但我找不到任何文档来执行此操作。

Please note that I'm not interested in answers that involve adding extra file input fields with different names. 请注意,我对涉及添加具有不同名称的额外文件输入字段的答案不感兴趣。 This is trivial to handle on the server, and my question doesn't involve front-end scripting at all. 这在服务器上处理是微不足道的,我的问题根本不涉及前端脚本。

Use the multiple attribute (in the form as you described) and then, after submission, call the Apache request object's upload method . 使用multiple属性(在您描述的表单中),然后在提交后调用Apache请求对象的upload方法 That will give you a list of Apache2::Upload instances. 这将为您提供Apache2::Upload实例的列表。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM