Upload multiple files (the File Upload box can be dynamically added in php + js)

Source: Internet
Author: User

Upload multiple files (the File Upload box can be dynamically added in php + js)

Upload multiple files (the File Upload box can be dynamically added for php tutorials and webpage special effects)
<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<Html xmlns = "http://www.bkjia. com1999/xhtml">

<Head>
<Meta content = "text/html; charset = gb2312" http-equiv = "content-type"/>
<Title> upload multiple files (a file upload box can be dynamically added for php + webpage special effects) </title>
<Script language = "webpage effect" type = "text/Webpage effect">
Function addinput () // Add an input node
{
Var input = document. createelement ('input'); // create an input node
Var br = document. createelement ('br '); // create a br Node
Input. setattribute ('type', 'file'); // you can specify the type attribute of an input node as file.
Input. setattribute ('name', 'pic [] '); // set the name attribute of the input node to files [] and pass it to the server as an array.
Document. form1.appendchild (br); // Add the node to the form1 form
Document. form1.appendchild (input );
}
</Script>
</Head>
<? Php
If ($ _ post ['sub'])
{
$ Ftype = array ('image/jpg ', 'image/jpeg', 'imgage/png ', 'image/pjpeg', 'image/gif '); // file type that can be uploaded
$ Files = $ _ files ['files'];
$ Fnum = count ($ files ['name']); // obtain the number of uploaded files
For ($ I = 0; $ I <$ fnum; $ I ++)
{
If ($ files ['name'] [$ I]! = ''& Is_uploaded_file ($ files ['tmp _ name'] [$ I])
{
If (in_array ($ files ['type'] [$ I], $ ftype) // checks whether the object type is allowed.
{
$ Fname = 'upfile /'. rand (0,10000 ). time (). substr ($ files ['name'] [$ I], strrpos ($ files ['name'] [$ I], '. '); // automatic name
Move_uploaded_file ($ files ['tmp _ name'] [$ I], $ fname );
Echo '<br/> the file is uploaded successfully! ';
}
Else
{
Echo '<br/> the file type is not allowed! ';
}
}
Else
{
Echo '<br/> the file does not exist! ';
}
}

}
?>
<Body>
<Form name = "form1" method = "post" action = "" enctype = "multipart/form-data">
<Input type = "file" name = "pic []"/>
<Input type = "submit" name = "sub" value = "Upload"/>
</Form>
<A href = "#" onclick = "addinput ()"> upload another file </a>
</Body>

</Html>


Related Article

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.