php 多文件上传的实现实例

(编辑:jimmy 日期: 2024/10/2 浏览:2)

首先向大家讲解一下实现的方法。

要实现多文件上传,我们可以在form表单中添加多个input file域,然后将这些input file的name属性设置为相同的名称且使用数组的形式命名,例如filename[]。至于文件上传的php代码和单个文件上传是一样的道理。

下面看一个多文件上传的实例:

html文件example.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<form action="my_parser.php" method="post" enctype="multipart/form-data">
 <p><input type="file" name="file_array[]"></p>
 <p><input type="file" name="file_array[]"></p>
 <p><input type="file" name="file_array[]"></p>
 <input type="submit" value="Upload all files">
</form>
</body>
</html>

php文件my_parser.php

<"test_uploads/".$name_array[$i])){
      echo $name_array[$i]." upload is complete<br>";
    } else {
      echo "move_uploaded_file function failed for ".$name_array[$i]."<br>";
    }
  }
}
?>

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!