I am trying to upload multiple files with PHP. I have put the multiple attribute in the corresponding input but when uploading the files and doing a var_dump of the array I discover that it only keeps the last file added. I don't know what could be going on.
This is the index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Editor de textos </title>
</head>
<body>
<form action="gestor.php" method="post" enctype="multipart/form-data">
<input type="file" name="archivos" id="archivos" multiple> <br> <br>
<input type="submit" value="Enviar">
</form>
</body>
</html>
This is where I collect the files.
And this is the manager.php
<?= $archivos["archivos"] = $_FILES["archivos"]; ?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> nube </title>
</head>
<body>
<ul>
<?php
foreach($archivos as $archivo) {
echo "<li>".$archivo['name']."</li>";
}
?>
</ul>
</body>
</html>
And this is the output it gives me
If you want to upload several files in an array, you must put the name as such.
That is, instead of this:
put it like this:
And in the loop put it like this:
Let us know if it worked for you.