如何使此上传脚本适用于多个上传选项?

时间:2016-05-09 19:13:58

标签: php html css html5 css3

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

<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>

1 个答案:

答案 0 :(得分:0)

你可以试试 姓名+ []

item

或使用多重

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

而不是通过文件循环你的PHP代码