多个文件上传(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>
<!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>
相关文章推荐
- PHP+Ajax实现上传文件进度条动态显示进度功能
- PHP动态网页设计(第2版)——上传文件
- 【Java EE 学习 72 上】【数据采集系统第四天】【增加调查logo】【文件上传】【动态错误页指定】【上传限制】【国际化】
- php 动态多文件上传
- PHP(14) 文件上传(含动态文件) 推荐
- 动态增加文件上传框
- js 动态增加file实现多文件上传功能并显示路径
- php的curl,uploadfile上传文件,xml解析,邮件发送,动态时间,去重,等
- 动态增加附件上传文件框的实现
- PHP动态多文件上传的具体代码分享
- php动态多文件上传
- 动态增加文件上传域
- php+js实现多文件上传
- 多文件上传(动态增加 FileUpload)
- php动态上传多文件
- php 动态多文件上传
- 实例:动态增加和删除上传文件的文本框
- PHP动态多文件上传的具体代码
- php环境架设后不能上传文件的问题
- 【代码】php 怎样实现单个文件上传