当前位置: 移动技术网 > IT编程>开发语言>PHP > php 动态多文件上传

php 动态多文件上传

2019年05月09日  | 移动技术网IT编程  | 我要评论

盘状红斑狼疮症状,窗帘挂杆,苍空 blue sky

文件上传代码
view plaincopy to clipboardprint?
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>文档上传</title>
</head>
<body>
<script language="javascript"><!--
动态添加文件选择控件-->
function addrow()
{
var enewrow = tbldata.insertrow();
for (var i=0;i<1;i++)
{
var enewcell = enewrow.insertcell();
enewcell.innerhtml = "<tr><td><input type='file' name='filelist[]' size='50'/></td></tr>";
}
}
// --></script>
<form name="myform" method="post" action="uploadfile.php" enctype="multipart/form-data" >
<table id="tbldata" width="400" border="0">
<!-- 将上传文件必须用post的方法和enctype="multipart/form-data" -->
<!-- 将本页的网址传给uploadfile.php-->
<input name="postadd" type="hidden" value="<?php echo "http://".$_server['http_host'].$_server["php_self"]; ?>" />
<tr><td>文件上传列表
<input type="button" name="addfile" onclick="addrow()" value="添加列表" /></td></tr>
<!-- filelist[]必须是一个数组-->
<tr><td><input type="file" name="filelist[]" size="50" /></td></tr>
</table>
<input type="submit" name="submitfile" value="提交文件" />
</form>
</body>
</html>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>文档上传</title>
</head>
<body>
<script language="javascript"><!--
动态添加文件选择控件-->
function addrow()
{
var enewrow = tbldata.insertrow();
for (var i=0;i<1;i++)
{
var enewcell = enewrow.insertcell();
enewcell.innerhtml = "<tr><td><input type='file' name='filelist[]' size='50'/></td></tr>";
}
}

// --></script>
<form name="myform" method="post" action="uploadfile.php" enctype="multipart/form-data" >
<table id="tbldata" width="400" border="0">
<!-- 将上传文件必须用post的方法和enctype="multipart/form-data" -->
<!-- 将本页的网址传给uploadfile.php-->
<input name="postadd" type="hidden" value="<?php echo "http://".$_server['http_host'].$_server["php_self"]; ?>" />
<tr><td>文件上传列表
<input type="button" name="addfile" onclick="addrow()" value="添加列表" /></td></tr>
<!-- filelist[]必须是一个数组-->
<tr><td><input type="file" name="filelist[]" size="50" /></td></tr>
</table>
<input type="submit" name="submitfile" value="提交文件" />
</form>
</body>
</html>
提交文件代码
view plaincopy to clipboardprint?
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>文件上传结果</title>
</head>
<body>
<?php
if ($_post["submitfile"]!="")
{
$path="./".date('ym')."/";
if (!is_dir($path))//创建路径
{ mkdir($path); }
echo "<div>";
for ($i=0;$i<count($filelist);$i++)
{ //$_files["filelist"]["size"][$i]的排列顺序不可以变,因为fileist是一个二维数组
if ($_files["filelist"]["size"][$i]!=0)
{
$file=$path.date('ymdhm')."_".$_files["filelist"]["name"][$i];
if (move_uploaded_file($_files["filelist"]["tmp_name"][$i],$file))
{ echo "文件上传成功 文件类型:".$_files["filelist"]["type"][$i]." "."文件名:"
.$_files["filelist"]["name"][$i]."<br>"; }
else
{ echo "文件名:".$_files["filelist"]["name"][$i]."上传失败</br>"; }
}
}
echo "</div><br><a href="$postadd" href="$postadd">返回</a></div>";
}
?>
</body>
</html>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网