您的位置:首页 > 编程语言 > PHP开发

多个文件上传(php+js可动态增加文件上传框)

2013-09-05 19:25 621 查看
多个文件上传(php+js可动态增加文件上传框)多个文件上传(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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: