I wish that you can choose only one file for each input and upload them all and apart from inserting certain data, I have the following code:
<?php
session_start();
$folders = $conn->query("SELECT * FROM 'folders' ORDER BY 'id' ASC");
$tfolders = $folders->num_rows;
$users = $conn->query("SELECT * FROM 'users' ORDER BY 'id' ASC");
if (isset($_POST['sfile'])) {
while($row=$folders->fetch_array()) {
$target_dir = "files/".$_SESSION['zona']."/";
$extension = '.' . pathinfo($_FILES[$row['id']]["name"],PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES[$row['id']]["tmp_name"], "files/". $_SESSION['zona'] . "/" . $row['name'] . $extension)) {
$stmt = $conn->prepare("INSERT INTO 'upfiles' ('name', 'extension', 'folderid', 'zona') VALUES (?, ?, ?, ?)") or trigger_error($conn->error);
$stmt->bind_param("ssis", $name, $extension, $folderid, $zona);
$name = $row['name'];
$folderid = $row['id'];
$zona = $_SESSION['zona'];
$stmt->execute();
$stmt->close();
}
$func->redirect('index.php');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Prueba</title>
</head>
<body>
<main style="text-align: center;">
<?php
echo "<form method='POST' enctype='multipart/form-data'>";
while($row=$folders->fetch_array())
{
$id = $row['id'];
$name = $row['name'];
echo "<input type='file' name='".$id."' id='selectedFile".$id."' style='display: none;' />";
echo "<input type='hidden' name='fid".$id."' value='".$id."'/>";
echo '<div id="button'.rand(1,10).'" class="boton" onclick="document.getElementById(\'selectedFile'.$id.'\').click();">'.$name.'</div>';
}
echo "<br><button type='submit' name='sfile'>Enviar archivos</button></form>";
?>
</main>
</body>
</html>
The problem here is that if I select all the files in each of the inputs, only the first one is uploaded, some ideas?