PHP dynamic multi-File Upload

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.