Home >Backend Development >PHP Tutorial >html - How to get multiple input values with the same name on the page in php
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
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
Front-end: <input type="hidden" name = "imgs[]" >
Back-end: print_r( $_POST["imgs"]);