<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name=description content="">
<meta name=viewport content="width=device-width, initial-scale=1">
<title>多文件上传</title>
<style>
table tr td{width:200px;height:30px;}
table tr{text-align:center;}
</style>
</head>
<body>
<form action="index.php" method="post" accept-charset="utf-8" enctype="multipart/form-data" name="form1">
<table border="1">
<tbody>
<tr>
<td>内容1</td><td><input type="file" name="picture[]"></td>
</tr>
<tr>
<td>内容2</td><td><input type="file" name="picture[]"></td>
</tr>
<tr>
<td>内容3</td><td><input type="file" name="picture[]"></td>
</tr>
<tr>
<td>内容4</td><td><input type="file" name="picture[]"></td>
</tr>
<tr>
<td>操作</td>
<td><input type="submit" name="submit" value="提交"></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
<?php
//判断服务器是否存在uploads文件,不存在则创建一个
if(!is_dir("./uploads")){
mkdir("./uploads");
}
//删除上传的图片重复的部分
$array=array_unique($_FILES['picture']['name']);
foreach ($array as $key => $value) {
$path="uploads/".$value;
if($value){
if(move_uploaded_file($_FILES['picture']['tmp_name'][$key],$path)){
$result=true;
}else{
$result=false;
}
}
}
if($result){
echo "文件上传成功";
echo "<meta http-equiv=\"refresh\" content=\";url=index.php\">";
}else{
echo "文件上传失败";
echo "<meta http-equiv=\"refresh\" content=\";url=index.php\">";
}
?>