多个文件上传(php+js可动态增加文件上传框)
多个文件上传(php+js可动态增加文件上传框)
多个php文件上传/ target=_blank >文件上传(php教程+网页特效可动态增加文件上传框)
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.php100.com1999/xhtml">
<head>
<meta content="text/html; charset=gb2312" http-equiv="content-type" />
<title>多个文件上传(php+网页特效可动态增加文件上传框)</title>
<script language="网页特效" type="text/网页特效">
function addinput()//增加input节点
{
var input=document.createelement(input);//创建一个input节点
var br=document.createelement(br);//创建一个br节点
input.setattribute(type,file);// 设置input节点type属性为file
input.setattribute(name,pic[]);//设置input节点 name属性为files[],以 数组的方式传递给服务器端
document.form1.appendchild(br);//把节点添加到 form1表单中
document.form1.appendchild(input);
}
</script>
</head>
<?php
if($_post[sub])
{
$ftype=array(image/jpg,image /jpeg,imgage/png,image/pjpeg,image/gif);//允许上传的文件类型
$files=$_files[files];
$fnum=count($files[name]); //取得上传文件个数
for($i=0;$i<$fnum;$i++)
{
if($files[name][$i]!=&&is_uploaded_file($files[tmp_name][$i]))
{
if(in_array($files[type][$i],$ftype))//判断文件是否是允许的类型
{
$fname=upfile/.rand(0,10000).time().substr($files[name] [$i],strrpos($files[name][$i],.));//自动命名
move_uploaded_file($files[tmp_name][$i],$fname);
echo <br/>文件上传成功!;
}
else
{
echo <br/>不允许的文件类型!;
}
}
else
{
echo <br/>该文件不存在!;
}
}
}
?>
<body>
<form name="form1" method="post" action="" enctype="multipart/form-data" >
<input type="file" name="pic[]" />
<input type="submit" name="sub" value="上传"/>
</form>
<a href="#" onclick="addinput()">再上传一张</a>
</body>
</html>
本文地址:http://www.phprm.com/frame/php1005089.html
转载随意,但请附上文章地址:-)