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>