php - $_FILES 仅包含最后一个输入

标签 php html forms codeigniter file-upload

我一整天都在与这个问题搏斗,厌倦了被困住。今天早上花了半个小时在我现在坚持使用的同一个应用程序上为个人资料图片做了一个不错的小型自定义 uploader 。

这里的问题不是上传(我已经把它放下了),而是将其扩展为允许多次上传的表单。它不是一个多文件、单输入 uploader ,而是具有多个输入。

目前,表单中只有两个 input type='file' 实例。我正在使用 Codeigniter,但问题不在于 CI 无法处理多个上传(我不认为)。我现在要做的就是简单地执行 print_r($_FILES); ,它只显示两个输入中的第二个

如果我在表单中交换它们的位置,它仍然只显示最后一个而不是两者。

今天我已经检查了他们的名字等大约 100 次。真的不确定发生了什么事。而且,需要明确的是,我一直在 SO 和 Google 中搜索,看看是否能找到问题。到目前为止我还没有想出任何办法。

感谢您的指导或帮助。

编辑:----------------------------

<form action="http://curvo:8888/index.php/offers/create" method="post" accept-charset="utf-8" class="bigolform" id="offer-form" enctype="multipart/form-data">                  
                    ...
                    <input type="file" name="ProductOfferPhoto" value="" id="ProductOfferPhoto">                    

                    ...

                    <input type="file" name="QuoteDoc" value="" id="QuoteDoc">                      

                    <!--using an ajax uploading script-->
                    <script type="text/javascript" src="/assets/js/libs/ajaxfileupload.js"></script>


                    <a href="#" class="orange btn add submit-the-offer">Complete offer</a>

</form>

我也尝试过使用genericName[],但这只能得到一个空数组。

最佳答案

确保您的输入name如果您接受多个文件,则是一个数组:

单个上传:
<input name="productImage" accept="image/*" type="file" />

多次上传:
<input name="productImage[]" accept="image/*" type="file" />
<input name="productImage[]" accept="image/*" type="file" />
... --------------------------------------^ []表示这是一个数组,并允许您为同一名称提交多个值。

然后你会发现 $_FILES 的多个值而不是仅上传最后一个文件(因为每个文件基本上都会覆盖当前的最后一个文件)

关于php - $_FILES 仅包含最后一个输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16326266/

相关文章:

php - php中使用mysql的多语言实现

html - 隐藏元素中除图像之外的所有内容

javascript - 如何在没有确认页面的情况下提交Google表单数据?

php - Twig_Error_Syntax : Unknown "template_from_string" function. 函数已过时?

php - 此选择更新是否需要回滚(不返回行)?

javascript - Fabric JS : Why are my shapes are being replaced with images on canvas

html - 如何使用@Media 查询

forms - VB6 .frm 文件格式属性无故更改!

jquery - 在 Firefox 中,如何强制光标停留在最后输入的字符上?

php - 如何定义 SoapVar 命名空间?