What are the potential issues with using multiple name attributes in an input element for file uploads in PHP?

Using multiple name attributes in an input element for file uploads in PHP can lead to confusion and potential errors when trying to access the uploaded files. To solve this issue, you can use the array syntax for the name attribute, which allows you to easily handle multiple file uploads as an array in PHP.

<form method="post" enctype="multipart/form-data">
    <input type="file" name="files[]" multiple>
    <input type="submit" value="Upload">
</form>

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $files = $_FILES['files'];

    foreach ($files['tmp_name'] as $key => $tmp_name) {
        $file_name = $files['name'][$key];
        $file_size = $files['size'][$key];
        $file_type = $files['type'][$key];
        $file_error = $files['error'][$key];
        
        // Process each uploaded file here
    }
}
?>