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
Release: 2016-08-04 09:20:37
Original
1207 people have browsed it

html code:

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


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

php code:

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

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>
Copy after login
Copy after login

php code:

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

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>
Copy after login

`

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>
Copy after login

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"]);

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template