How to add multiple product gallery images from front-end

if ( ! empty( $_FILES['muti_files'] )  ) {
            $files = $_FILES['muti_files'];
            foreach ($files['name'] as $key => $value){
                if ($files['name'][$key]){
                    $file = array(
                    'name' => $files['name'][$key],
                    'type' => $files['type'][$key],
                    'tmp_name' => $files['tmp_name'][$key],
                    'error' => $files['error'][$key],
                    'size' => $files['size'][$key]
                    );
                }
                $_FILES = array("muti_files" => $file);
                $i=1;
                    foreach ($_FILES as $file => $array) {
                          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');
                            $attachment_id = media_handle_upload($file, $post_id);
                            $vv .= $attachment_id . ",";
                            $i++;
                    }
                    update_post_meta($post_id, '_product_image_gallery',  $vv);
            }
        }