Home >Backend Development >PHP Tutorial >html - How to get multiple input values ​​with the same name on the page in php

html - How to get multiple input values ​​with the same name on the page in php

WBOY
WBOYOriginal
2016-08-04 09:20:371194browse

html code:

<code><input type="file" name = "imgs[]" >
<input type="file" name = "imgs[]" >


<input type="file" name = "imgs[]" >
</code>

php code:

<code>$imgs = $_FILES['imgs'];</code>

In this case, I can only get the first one. Please tell me how to get them all. I submitted them through the form

Reply content:

html code:

<code><input type="file" name = "imgs[]" >
<input type="file" name = "imgs[]" >


<input type="file" name = "imgs[]" >
</code>

php code:

<code>$imgs = $_FILES['imgs'];</code>

In this case, I can only get the first one. Please tell me how to get them all. I submitted them using the form

`

<code>foreach($_FILES['imgs']['name'] as $key => $row ){
    echo $_FILES['imgs']['name'][$key];
}
</code>

`

Use it another way:

<code><input type="text" name = "imgs1" >
<input type="text" name = "imgs2" >
<input type="text" name = "imgs3" >

<php>
dump(trim($_POST['imgs1']));
dump(trim($_POST['imgs2']));
dump(trim($_POST['imgs3']));
</php></code>

The method on the first floor is fine! Pass it to the background as an array and process it!

Use Ajax to upload, directly return the front-end image url... and then put it in the input box
html - How to get multiple input values ​​with the same name on the page in php
Front-end: <input type="hidden" name = "imgs[]" >
Back-end: print_r( $_POST["imgs"]);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn