PHP dynamic multi-file upload code sharing

Source: Internet
Author: User

You areUpload File Code:

 
 
  1. <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <Html Xmlns=Http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Meta Http-equiv="Content-Type" Content="Text/html; charset = gb2312" />
  5. <Title>Document Upload</Title>
  6. </Head>
  7. <Body>
  8. <Mce: script Language="Javascript"><! -- 
  9. Dynamically Add a file selection control -->
  10. Function AddRow ()
  11. {
  12. VarENewRow=TblData. InsertRow ();
  13. For (varI=0; I<1; I ++)
  14. {
  15. VarENewCell=ENewRow. InsertCell ();
  16. ENewCell. innerHTML="<Tr> <td> <input type = 'file' name = 'filelist [] 'size = '50'/> </td> </tr>";
  17. }
  18. }
  19. //--></Mce: script>
  20. <Form Name="Myform" Method="Post" Action="Uploadfile. php" Enctype="Multipart/form-data" >
  21. <Table Id="TblData" Width="400" Border="0">
  22. <! -- The post method and enctype = "multipart/form-data" must be used to upload files. -->
  23. <! -- Pass the URL on this page to uploadfile. php -->
  24. <Input Name="Postadd" Type="Hidden" Value="<?PhpEcho"Http: // ". $ _ SERVER ['HTTP _ host']. $ _ SERVER [" PHP_SELF "];?>"/>
  25. <Tr><Td>File Upload list
  26. <Input Type="Button" Name="Addfile"Onclick="AddRow ()" Value="Add list" /></Td></Tr>
  27. <! -- Filelist [] must be an array -->
  28. <Tr><Td><Input Type="File" Name="Filelist []" Size="50" /></Td></Tr>
  29.  </Table>
  30. <Input Type="Submit" Name="Submitfile" Value="Submit file" />
  31.  </Form>
  32. </Body>
  33. </Html>

PHP code for submitting dynamic multi-file upload:

 
 
  1. <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN ""
    Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <Html Xmlns=Http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Meta Http-equiv="Content-Type" Content="Text/html; charset = gb2312" />
  5. <Title>File Upload result</Title>
  6. </Head>
  7. <Body>
  8. <?Php
  9. If ($ _ POST ["submitfile"]! = "")
  10. {
  11. $Path="./". Date ('ym ')."/";
  12. If (! Is_dir ($ Path) // create a Path
  13. {Mkdir ($ Path );}
  14. Echo"<Div>";
  15. For ($I=0; $ I<Count($ Filelist); $ I ++)
  16. {// $ _ FILES ["filelist"] ["size"] [$ I] cannot be changed,
    Because fileist is a two-dimensional array
  17. If ($ _ FILES ["filelist"] ["size"] [$ I]! = 0)
  18. {
  19. $File= $ Path. date ('ymdhm'). "_". $ _ FILES ["filelist"] ["name"] [$ I];
  20. If (move_uploaded_file ($ _ FILES ["filelist"] ["tmp_name"] [$ I], $ File ))
  21. {Echo "file type:". $ _ FILES ["filelist"]
    ["Type"] [$ I]. "". "file name :"
  22. . $ _ FILES ["filelist"] ["name"] [$ I]."<Br>";}
  23. Else
  24. {Echo "file name:". $ _ FILES ["filelist"] ["name"] [$ I]. "Upload Failed</Br>";}
  25. }
  26. }
  27. Echo"</Div><Br><A Href="$ Postadd" Mce_href="$ Postadd">Return</A></Div>";
  28. }
  29. ?>
  30. </Body>
  31. </Html>

The above is all PHP code for dynamic multi-file upload.


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.