多文件上传器只发送一个文件

时间:2022-02-20 07:28:13

I have a multiple file input which I'm able to select multiple files but when I var_dump the file variable on the form action page there's only ever one file.

我有一个多文件输入,我可以选择多个文件但是当我在表单操作页面上var_dump文件变量时,只有一个文件。

<input id="image" type="file" name="images" multiple="multiple">

Here's the dump var_dump($_FILES);

这是dump var_dump($ _ FILES);

array(1) { ["images"]=> array(5) { ["name"]=> string(12) "IMG_4511.JPG" ["type"]=> string(10) "image/jpeg" ["tmp_name"]=> string(26) "/private/var/tmp/php8g7CV3" ["error"]=> int(0) ["size"]=> int(730250) } }

Here's the opening form tag:

这是开场表格标签:

<form enctype="multipart/form-data" method="POST" action="http://localhost.com/item/update" accept-charset="UTF-8">

Is there anything I'm missing here?

这里有什么我想念的吗?

2 个解决方案

#1


1  

<input id="image" type="file" name="images[]" multiple="multiple">

Should work

应该管用

#2


0  

Make sure your input name is an array if you are accepting multiple files:

如果您接受多个文件,请确保您的输入名称是数组:

Single upload:
<input name="productImage" accept="image/*" type="file" />

单上传:

Multiple uploads:
<input name="productImage[]" accept="image/*" type="file" />
<input name="productImage[]" accept="image/*" type="file" />
... --------------------------------------^ The [] signifies this is an array and allows you to submit multiple values for the same name.

多次上传:。 .. -------------------------------------- ^ []表示这是一个数组而且允许您为同一个名称提交多个值。

Then you will find multiple values for $_FILES instead of only the last file uploaded (as each file is basically overriding the last currently)

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

#1


1  

<input id="image" type="file" name="images[]" multiple="multiple">

Should work

应该管用

#2


0  

Make sure your input name is an array if you are accepting multiple files:

如果您接受多个文件,请确保您的输入名称是数组:

Single upload:
<input name="productImage" accept="image/*" type="file" />

单上传:

Multiple uploads:
<input name="productImage[]" accept="image/*" type="file" />
<input name="productImage[]" accept="image/*" type="file" />
... --------------------------------------^ The [] signifies this is an array and allows you to submit multiple values for the same name.

多次上传:。 .. -------------------------------------- ^ []表示这是一个数组而且允许您为同一个名称提交多个值。

Then you will find multiple values for $_FILES instead of only the last file uploaded (as each file is basically overriding the last currently)

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