我有一个包含以下代码的HTML表单:
<input id="image_22" name="images[]" type="file" />
<input id="image_8" name="images[]" type="file" />
我希望能够将表单输入 ID 元素存储在变量中(例如 $imgnumber = 'image_22')。这可能吗?在下面的代码中查看我的评论:
PHP:
for ($i = 0; $i < count($_FILES['images']['name']); $i++) {
$number_of_file_fields++;
if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not
$number_of_uploaded_files++;
$uploaded_files[] = $_FILES['images']['name'][$i];
if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) {
$number_of_moved_files++;
// *** COMMENT *** //
$imgnumber = CURRENT_FILE_INPUT_ID - this would store e.g. "image_22"
}
}
}
非常感谢您对此的任何帮助:-)