<html>
<head>
<title>HTML Form for uploading image to server</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</p>
</form>
<?php
//places files into same dir as form resides
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
echo"$error_codes[$error]";
move_uploaded_file(
$_FILES["pictures"]["tmp_name"][$key],
$_FILES["pictures"]["name"][$key]
) or die("Problems with upload");
}
}
?>
</body>
</html>
<head>
<title>HTML Form for uploading image to server</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</p>
</form>
<?php
//places files into same dir as form resides
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
echo"$error_codes[$error]";
move_uploaded_file(
$_FILES["pictures"]["tmp_name"][$key],
$_FILES["pictures"]["name"][$key]
) or die("Problems with upload");
}
}
?>
</body>
</html>
<HTML>
<HEAD>
<TITLE> 动态增加文件上传域</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<script language="javascript" type="text/javascript">
function addfile(){
var str='<input type="file" name="file" size="20"><br>'; document.getElementById("myfile").insertAdjacentHTML("beforeEnd",str);
} </script>
<input type="button" value="增行" onclick="addfile()"/>
<a id="myfile">
<input type="file" name="file"><br/></a>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> 动态增加文件上传域</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<script language="javascript" type="text/javascript">
function addfile(){
var str='<input type="file" name="file" size="20"><br>';
document.getElementById("myfile").insertAdjacentHTML("beforeEnd",str);
}
function delfile(){
document.getElementById("file").removeNode(true) ;
}
</script>
<input type="button" value="增行" onclick="addfile()"/>
<input type="button" value="减行" onclick="delfile()"/>
<a id="myfile">
<input type="file" name="file" id="file"><br/></a>
</BODY>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 动态增加文件上传域</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<form>
<input type="button" onclick="addline()" value="增加一行">
<table border="0" id="test">
<tr>
<td colspan="2"><input type="file" name="myfile"></td>
</tr>
</table>
<input type="submit">
</form>
<script>
function addline(content){
newline=document.all.test.insertRow();
newline.insertCell().innerHTML='<input type="file" name="myfile"><input type="button" value="删除此行" onclick="del()">'
}
function del(){
document.all.test.deleteRow(window.event.srcElement.parentElement.parentElement.rowIndex);
}
</script>
</BODY>
</HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script>
var $ = function(id)
{
return document.getElementById(id);
}
var add_input = function()
{
var _tr = document.createElement("tr");
var _td = document.createElement("td");
var _input = document.createElement("input");
_input.type ="file";
_td.appendChild(_input);
_tr.appendChild(_td);
if(document.all)//IE
{
$("files").childNodes[0].appendChild(_tr);
}
else//firefox
{
$("files").appendChild(_tr);
}
}
var remove_input = function()
{
if(document.all)//ie
{
$("files").childNodes[0].removeChild($("files").childNodes[0].lastChild);
}
else//firefox
{
$("files").removeChild($("files").lastChild);
}
}
window.onload = function()
{
if(document.all)
{
document.getElementsByTagName("input")[1].attachEvent("onclick",add_input);
document.getElementsByTagName("input")[2].attachEvent("onclick",remove_input);
}
else
{
document.getElementsByTagName("input")[1].addEventListener("click",add_input,false);
document.getElementsByTagName("input")[2].addEventListener("click",remove_input,false);
}
}</script>
<body>
<table id="files">
<tr>
<td>
<input type="file" />
</td>
</tr>
</table>
<input type="button" />
<input type="button" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title></title>
</head>
<script language="javascript">
function chick(){
var _count = document.getElementById("files").getElementsByTagName("input");
var len = _count.length - 1;
var _obj = _count[len];
var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;
if (ie) {
_obj.click();
}
else {
var a = document.createEvent("MouseEvents");
a.initEvent("click", true, true);
_obj.dispatchEvent(a);
}
var _path = _obj.value;
var _parent = document.getElementById("path_table").firstChild;
var row = document.createElement("tr");
row.setAttribute("id",len);
var cell1 = document.createElement("td");
cell1.style.borderBottom = "solid";
cell1.style.borderBottomWidth = "1px";
var cell2 = document.createElement("td");
cell2.style.borderBottom = "solid";
cell2.style.borderBottomWidth = "1px";
var _a = document.createElement("a");
_a.innerHTML = "取消";
_a.href = "javascript:remove("+len+")";
var _text = document.createTextNode(_path);
cell1.appendChild(_text);
cell2.appendChild(_a);
row.appendChild(cell1);
row.appendChild(cell2);
_parent.appendChild(row);
}
function create(){
//统计现有input
var length = document.getElementById("files").getElementsByTagName("input").length;
var _id = "";
if (length == 0) {
_id = "0"
} else {
_id = length;
}
//添加一个新的INPUT
var _td = document.getElementById("input_td");
var _input = document.createElement("input");
_input.setAttribute("type", "file");
_input.setAttribute("name", "pics[]");
alert(_input.getAttribute('name'));
_input.setAttribute("id", _id);
_td.appendChild(_input);
chick();
}
function remove(obj) {
var _rem = document.getElementById(obj);
var _remt = document.getElementById("path_table").firstChild;
_remt.removeChild(_rem);
var _inputs = document.getElementById("files").getElementsByTagName("input");
for (var i = 0; i < _inputs.length; i++) {
var tmp = _inputs[i];
if (tmp.getAttribute("id") == obj) {
document.getElementById("input_td").removeChild(tmp);
break;
}
}
}
</script>
<body>
<form name="fileupload" method="post" action="uploadservlet.php" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" border="0" width="600">
<tr>
<td>
文件上传
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0"
width="100%" id="path_table" style="border-bottom:solid; border-bottom-width:1px;">
<tr id="first_tr">
<td width="80%" style="border-bottom:solid; border-bottom-width:1px;">
文件路径
</td>
<td width="20%" style="border-bottom:solid; border-bottom-width:1px;">
操作
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<input name="button" type="button" onclick="create();" value="选择文件" />
<input type="submit" value="提交" />
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" id="files" style="display:none;">
<tr>
<td id="input_td">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
这个可好?