File Upload Code
View plaincopy to clipboardprint?
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> Document Upload </title>
</Head>
<Body>
<Script language = "JavaScript"> <! --
Dynamically Add 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 = '50'/> </TD> </tr> ";
}
}
// --> </SCRIPT>
<Form name = "myform" method = "Post" Action = "uploadfile. php" enctype = "multipart/form-Data">
<Table id = "tbldata" width = "400" border = "0">
<! -- The POST method and enctype = "multipart/form-Data" must be used to upload files. -->
<! -- Pass the URL on this 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 = "50"/> </TD> </tr>
</Table>
<Input type = "Submit" name = "submitfile" value = "Submit file"/>
</Form>
</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.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> Document Upload </title>
</Head>
<Body>
<Script language = "JavaScript"> <! --
Dynamically Add 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 = '50'/> </TD> </tr> ";
}
}
// --> </SCRIPT>
<Form name = "myform" method = "Post" Action = "uploadfile. php" enctype = "multipart/form-Data">
<Table id = "tbldata" width = "400" border = "0">
<! -- The POST method and enctype = "multipart/form-Data" must be used to upload files. -->
<! -- Pass the URL on this 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 = "50"/> </TD> </tr>
</Table>
<Input type = "Submit" name = "submitfile" value = "Submit file"/>
</Form>
</Body>
</Html>
Submit File Code
View plaincopy to clipboardprint?
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> File Upload result </title>
</Head>
<Body>
<? PHP
If ($ _ post ["submitfile"]! = "")
{
$ Path = "./". Date ('ym ')."/";
If (! Is_dir ($ PATH) // create a path
{Mkdir ($ PATH );}
Echo "<div> ";
For ($ I = 0; $ I <count ($ filelist); $ I ++)
{// $ _ FILES ["filelist"] ["size"] [$ I] cannot be changed 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 Uploaded successfully:". $ _ FILES ["filelist"] ["type"] [$ I]. "". "file name :"
. $ _ FILES ["filelist"] ["name"] [$ I]. "<br> ";}
Else
{Echo "file name:". $ _ FILES ["filelist"] ["name"] [$ I]. "Upload Failed </BR> ";}
}
}
Echo "</div> <br> <a href =" $ postadd "href =" $ postadd "> return </a> </div> ";
}
?>
</Body>
</Html>