<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
enewcell.innerhtml = "<tr><td><input type= ' file ' name= ' filelist[] ' size= '/></td></tr > ";
<form name= "MyForm" method= "post" action= "uploadfile.php" enctype= "Multipart/form-data" >
<!--will upload the file must use the Post method and enctype= "Multipart/form-data"-->
<input name= "Postadd" type= hidden "value=" <?php echo "http://" $_server["Http_host"].$_server["PHP_SELF"];? > "/>
<input type= "button" Name= "AddFile" onclick= "AddRow ()" value= "Add List"/></td></tr>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Document Upload </title>
<body>
<script language= "JavaScript" ><!--
Dynamically adding a file selection control-->
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= '/></td></tr > ";
}
}
--></script>
<form name= "MyForm" method= "post" action= "uploadfile.php" enctype= "Multipart/form-data" >
<table id= "Tbldata" width= "border=" "0" >
<!--will upload the file must use the Post method and enctype= "Multipart/form-data"-->
<!--the Web page to uploadfile.php-->
<input name= "Postadd" type= hidden "value=" <?php echo "http://" $_server["Http_host"].$_server["PHP_SELF"];? > "/>
<tr><td> File Upload List
<input type= "button" Name= "AddFile" onclick= "AddRow ()" value= "Add List"/></td></tr>
<!--filelist[] must be an array-->
<tr><td><input type= "File" name= "filelist[" "size="/></td></tr>
</table>
<input type= "Submit" Name= "Submitfile" value= "Submitting Documents"/>
</form>
</body>
Submit File Code
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> File Upload Results </title>
<body>
<?php
if ($_post["Submitfile"]!= "")
{
$Path = "./". Date (' Ym '). " /";
if (!is_dir ($Path))//create Path
{mkdir ($Path);}
echo "<div>";
for ($i =0; $i <count ($filelist); $i + +)
{//$_files["filelist"] ["size"] [$i] can not be arranged in order, because Fileist is a two-dimensional array
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 "File upload successful file type:". $_files["FileList"] ["type"] [$i]. " "." File name: "
. $_files["FileList" ["Name"] [$i]. " <br> "; }
Else
{echo "filename:". $_files["FileList"] ["name"] [$i]. " Upload Failure </br> "; }
}
}
echo "</div><br><a href=" $postadd "href=" $postadd "> Return </a></div>";
}
?>
</body>
The above example based on JS to dynamically increase the upload file box, so as to achieve multiple file upload function.
I hope this article will help you with your PHP program design.