我如何使这个上传脚本与多个上传选项一起工作


How do I make this upload script work with multiple upload options?

我想这样做,当将多个文件上传到目标文件夹时,您不仅有一个选择文件选项,而且有多个选择文件选择选项,可以一次上传所需数量的文件。它的目标是它目录中的一个文件夹,当我有一个选择文件输入时,它可以工作,但当添加更多文件时,它就不工作了。这是我迄今为止的代码。

<html> 
<head>
<?php
if(isset($_POST['Submit']))
{
$file_name = $_FILES['audio_file']['name'];
if($_FILES['audio_file']['type']=='audio/mpeg' || $_FILES['audio_file']['type']=='audio/mpeg3' || $_FILES['audio_file']['type']=='audio/x-mpeg3' || $_FILES['audio_file']['type']=='audio/mp3' || $_FILES['audio_file']['type']=='audio/x-wav' || $_FILES['audio_file']['type']=='audio/wav')
{ 
 $new_file_name=$_FILES['audio_file']['name'];
 $target_path = "audiofiles/".$new_file_name;
if(move_uploaded_file($_FILES['audio_file']['tmp_name'], $target_path)) {
}
}
}
?>
</head>
<body>
<form name="audio_form" id="audio_form" action="" method="post" enctype="multipart/form-data">
<fieldset style="height: 23vh; width: 50vw;">
<input name="audio_file" id="audio_file" type="file" style="position: fixed; top: 2vh;">
<input name="audio_file" id="audio_file" type="file" style="position: fixed; top: 7vh;">
<input name="audio_file" id="audio_file" type="file" style="position: fixed; top: 12vh;">
<input name="audio_file" id="audio_file" type="file" style="position: fixed; top: 17vh;">
<input name="audio_file" id="audio_file" type="file" style="position: fixed; top: 22vh;">
<input type="submit" name="Submit" id="Submit" value="Submit" style="position: fixed; top: 30vh;">
</fieldset>
</form>
</body> 
</html>

您可以尝试name+[]

<input name="audio_file[]" id="audio_file" type="file" style="position: fixed; top: 2vh;">

或使用属性多重

<input name="audio_file" id="audio_file" type="file" style="position: fixed; top: 2vh;" multiple>

然后在您的php代码中循环通过文件