You areUpload File Code:
- <! 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>
- <Mce: script Language="Javascript"><! --
- Dynamically Add a file selection control -->
- Function AddRow ()
- {
- VarENewRow=TblData. InsertRow ();
- For (varI=0; I<1; I ++)
- {
- VarENewCell=ENewRow. InsertCell ();
- ENewCell. innerHTML="<Tr> <td> <input type = 'file' name = 'filelist [] 'size = '50'/> </td> </tr>";
- }
- }
- //--></Mce: 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="<?PhpEcho"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>
PHP code for submitting dynamic multi-file upload:
- <! 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 type:". $ _ 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" Mce_href="$ Postadd">Return</A></Div>";
- }
- ?>
- </Body>
- </Html>
The above is all PHP code for dynamic multi-file upload.