Site icon Hip-Hop Website Design and Development

submit two file input fields in the same form

I have a form which has two file input fields, when I try to submit the form it takes only the first one and ignore the second one!

here is my form

<form method="POST" name="vendor_form" enctype="multipart/form-data">
 <div class="mb-3" style="margin-bottom: 20px;">
            <label for="file_metabox" class="form-label">file metabox</label>
            <input class="form-control" type="file" id="file_metabox" name="file_metabox[]" multiple="multiple">
        </div>
        <div class="mb-3" style="margin-bottom: 20px;">
            <label for="file_cert" class="form-label">file Cert</label>
            <input class="form-control" type="file" id="file_cert" name="file_cert[]" multiple="multiple">
        </div>
<button type="submit" class="btn btn-primary" id="submit" name="submit">Submit</button>

and here is the php

if (isset($_FILES['file_metabox'])) {
    $file_metabox = $_FILES['file_metabox'];
    foreach ($file_metabox['name'] as $key => $value) {
        if ($file_metabox['name'][$key]) {
            $file = array(
                'name' => $file_metabox['name'][$key],
                'type' => $file_metabox['type'][$key],
                'tmp_name' => $file_metabox['tmp_name'][$key],
                'error' => $file_metabox['error'][$key],
                'size' => $file_metabox['size'][$key]
            );
            $_FILES = array("file_metabox" => $file);
            foreach ($_FILES as $file => $array) {
                // $newupload = frontend_handle_attachment( $file, $post_success );
                if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) __return_false();

                require_once(ABSPATH . "wp-admin" . '/includes/image.php');
                require_once(ABSPATH . "wp-admin" . '/includes/file.php');
                require_once(ABSPATH . "wp-admin" . '/includes/media.php');

                $attach_id = media_handle_upload($file, $post_success);

                add_post_meta($post_success, 'file_metabox', $attach_id);
            }
        }
    }
   
}
if (isset($_FILES['file_cert'])) {
    $file_cert = $_FILES['file_cert'];
    foreach ($file_cert['name'] as $key => $value) {
        if ($file_cert['name'][$key]) {
            $file = array(
                'name' => $file_cert['name'][$key],
                'type' => $file_cert['type'][$key],
                'tmp_name' => $file_cert['tmp_name'][$key],
                'error' => $file_cert['error'][$key],
                'size' => $file_cert['size'][$key]
            );
            $_FILES = array("file_cert" => $file);
            foreach ($_FILES as $file => $array) {
                // $newupload = frontend_handle_attachment( $file, $post_success );
                if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) __return_false();

                require_once(ABSPATH . "wp-admin" . '/includes/image.php');
                require_once(ABSPATH . "wp-admin" . '/includes/file.php');
                require_once(ABSPATH . "wp-admin" . '/includes/media.php');

                $attach_id = media_handle_upload($file, $post_success);

                add_post_meta($post_success, 'file_cert', $attach_id);
            }
        }
    }
}