PHP › File Upload Handling
How do you handle multiple file uploads submitted from a single form field, and what does the resulting $_FILES array structure look like?
IntermediateAnswer
When a file input is configured to accept multiple files using an array style field name, the $_FILES superglobal organizes the data slightly differently, storing each attribute, such as name or tmp_name, as its own array containing one entry per uploaded file, meaning you typically need to loop through these parallel arrays using a shared numeric index to process each individual uploaded file correctly.
<input type="file" name="documents[]" multiple>
foreach ($_FILES['documents']['name'] as $index => $name) {
$tmpPath = $_FILES['documents']['tmp_name'][$index];
move_uploaded_file($tmpPath, 'uploads/' . $name);
}Real-world example A photo gallery upload feature lets users select and upload several images at once, looping through the resulting parallel arrays in $_FILES to process and store each individual uploaded photo correctly.