Hello everyone!

Interested in this solution puzzles. There is such a HTML code

<input type="text" name="comp" placeholder="Comp" /><br> <input type="text" name="name[]" placeholder="name1" /><br> <input type="text" name="desc[]" placeholder="desc1" /><br> <input type="file" name="files[]" multiple /><br> <input type="text" name="name[]" placeholder="name2" /><br> <input type="text" name="desc[]" placeholder="desc2" /><br> <input type="file" name="files[]" multiple /><br> 

How to create an array with the names of the files that were selected in the first or second input. There is a script almost working, but it has a defect that instead of the file name there is a hieroglyph

  $this_is_it = array(); $post = array_values($_POST); for($j = 0; $j < count($post[1]); $j++){ for($u = 0; $u < count($post[3]); $u++){ $this_is_it['order_' . ($j + 1)] = array( 'name' => $post[1][$j], 'desc' => $post[2][$j], 'attach' => $post[3][$j] ); } } 

It displays with this:

 array(2) { ["order_1"]=> array(3) { ["name"]=> string(4) "lala" ["desc"]=> string(7) "lalalal" ["attach"]=> string(1) " " } ["order_2"]=> array(3) { ["name"]=> string(5) "name2" ["desc"]=> string(5) "desc2" ["attach"]=> string(1) " " } } 

What to do how to be

  • one
    Maybe just hang id for input? Type value, or another hidden with the order ID. Something like that. - iKey

2 answers 2

 <form action="ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ.php" method="post"> <input type="text" name="name[]" value="name1" /> <input type="text" name="desc[]" value="desc1" /> <input type="file" name="files[]" multiple /> <input type="text" name="name[]" value="name2" /> <input type="text" name="desc[]" value="desc2" /> <input type="file" name="files[]" multiple /> </form> 

In this case, the handler will receive order and files arrays, in which data with the same keys will contain information about the same order. You need to sculpt them together and process them in your own way (to the database, by letter, etc.)

 ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ.php $this_is_it = array(); $post = array_values($_POST); for($i = 0; $i < count($post[0]); $i++){ for($j = 0; $j < count($post); $j++){ $this_is_it['order_' . ($i + 1)] = array( 'name' => $post[0][$i], 'desc' => $post[1][$i], 'attach' => $post[2][$i] ); } } 

Get an array of $ this_is_it, with grouped order data:

 array ( 'order_1' => array ( 'name' => 'name1', 'desc' => 'desc1', 'attach' => 'ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ°.jpg', ), 'order_2' => array ( 'name' => 'name2', 'desc' => 'desc2', 'attach' => 'ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ°_2.jpg', ), 

)

  • Hello, but it is possible with a piece of php code to show how it works, but I don’t get it - B. Aleksei
  • Completed the answer at your request. - Kirill Korushkin
  • I tried to use your system today, everything works fine and the inputs are divided into works, but if I add a file, then when displayed in var_dump (); I have in the attach field there is such a symbol " " maybe a question in the encoding or what else could be the problem? And when adding multiple files the same problem I can attach the file download code if interested. - B. Aleksei
  • show the form and var_dapm. What file extensions are used in the attachment and in what encoding? - Kirill Korushkin
  • I'll send you all the answer to your question - B. Aleksei
 Var_dump: array(2) { ["order_1"]=> array(3) { ["name"]=> string(4) "lala" ["desc"]=> string(7) "lalalal" ["attach"]=> string(1) " " } ["order_2"]=> array(3) { ["name"]=> string(5) "name2" ["desc"]=> string(5) "desc2" ["attach"]=> string(1) " " } } 

The form:

 <form action="" method="POST" enctype="multipart/form-data"> <div id="addtask"></div> <input type="text" name="name[]" value="name1" /><br> <input type="text" name="desc[]" value="desc1" /><br> <input type="file" name="files[]" multiple /><br> <input type="text" name="name[]" value="name2" /><br> <input type="text" name="desc[]" value="desc2" /><br> <input type="file" name="files[]" multiple /><br> <input type="submit" value="НаТми" name="enter"><br> </form> 

File extension: tried different extensions, main .png and still different, be sure to need extensions .cdr, .pdf, .png, .jpeg

I did not find the file encoding, but all the code was transferred to UTF-8 via notepad ++