Multiple file uploader only sends one file

2019-01-29 10:16发布

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.

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

Here's the 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条回答
干净又极端
2楼-- · 2019-01-29 10:30

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)

查看更多
爷、活的狠高调
3楼-- · 2019-01-29 10:32
<input id="image" type="file" name="images[]" multiple="multiple">

Should work

查看更多
登录 后发表回答