我有一个表单,它有两个文件输入字段,每个输入都应该在自定义帖子类型的不同元框中提交,当我尝试提交表单时,只会使用第一个,而忽略第二个!
这是我的表格
<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>
这里是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);
}
}
}
}