What best practices should be followed when iterating through multiple file uploads in PHP?

When iterating through multiple file uploads in PHP, it is important to properly handle each file upload individually to ensure that all files are processed correctly. One common approach is to use a loop to iterate through the $_FILES array and handle each file upload within the loop. Additionally, it is important to validate each file upload to ensure that it meets any necessary criteria, such as file type or size.

<?php
// Iterate through multiple file uploads
foreach ($_FILES['file']['name'] as $key => $name) {
    $file_name = $_FILES['file']['name'][$key];
    $file_tmp = $_FILES['file']['tmp_name'][$key];
    
    // Validate file upload
    if ($_FILES['file']['error'][$key] === UPLOAD_ERR_OK) {
        // Process file upload
        move_uploaded_file($file_tmp, "uploads/" . $file_name);
        echo "File uploaded successfully: " . $file_name . "<br>";
    } else {
        echo "Error uploading file: " . $file_name . "<br>";
    }
}
?>