How can I attach multiple files with form? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I attach multiple files with form?

these files should open according to the input

22nd Dec 2017, 5:00 PM
Mehak goyal
Mehak goyal - avatar
1 Answer
+ 3
This is possible in HTML5. Example (PHP 5.4): <!doctype html> <html> <head> <title>Test</title> </head> <body> <form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form> <?php if (isset($_FILES['my_file'])) { $myFile = $_FILES['my_file']; $fileCount = count($myFile["name"]); for ($i = 0; $i < $fileCount; $i++) { ?> <p>File #<?= $i+1 ?>:</p> <p> Name: <?= $myFile["name"][$i] ?><br> Temporary file: <?= $myFile["tmp_name"][$i] ?><br> Type: <?= $myFile["type"][$i] ?><br> Size: <?= $myFile["size"][$i] ?><br> Error: <?= $myFile["error"][$i] ?><br> </p> <?php } } ?> </body> </html> Here's what it looks like in Chrome after selecting 2 items in the file dialog:
22nd Dec 2017, 5:08 PM
James16
James16 - avatar