我是靠谱客的博主 含糊薯片,这篇文章主要介绍php 多文件上传的实现实例,现在分享给大家,希望可以做个参考。

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

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

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

html文件example.html

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php if(isset($_FILES['file_array'])){ $name_array = $_FILES['file_array']['name']; $tmp_name_array = $_FILES['file_array']['tmp_name']; $type_array = $_FILES['file_array']['type']; $size_array = $_FILES['file_array']['size']; $error_array = $_FILES['file_array']['error']; for($i = 0; $i < count($tmp_name_array); $i++){ if(move_uploaded_file($tmp_name_array[$i], "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>"; } } } ?>

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

最后

以上就是含糊薯片最近收集整理的关于php 多文件上传的实现实例的全部内容,更多相关php内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(98)

评论列表共有 0 条评论

立即
投稿
返回
顶部