PHP dynamic multi-file upload code sharing _ PHP Tutorial

Source: Internet
Author: User
PHP dynamic multi-file upload code sharing. The following code uploads a File :! DOCTYPEhtmlPUBLIC-W3CDTDXHTML1.0TransitionalENwww.w3.orgTRxhtml1DTDxhtml1-transitional.dtdhtmlxmlnswww.w everyone in through Upload file code:

 
 
  1. >
  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. Function AddRow ()
  10. {
  11. VarENewRow=TblData. InsertRow ();
  12. For (varI=0; I<1; I ++)
  13. {
  14. VarENewCell=ENewRow. InsertCell ();
  15. ENewCell. innerHTML="";
  16. }
  17. }
  18. //--> Mce: script>
  19. <Form Name="Myform" Method="Post" Action="Uploadfile. php" Enctype="Multipart/form-data" >
  20. <Table Id="TblData" Width="400" Border="0">
  21. <Input Name="Postadd" Type="Hidden" Value=" PhpEcho"Http: // ". $ _ SERVER ['http _ host']. $ _ SERVER [" PHP_SELF "];?>"/>
  22. <Tr><Td>File upload list
  23. <Input Type="Button" Name="Addfile" Onclick="AddRow ()" Value="Add List" /> Td> Tr>
  24. <Tr><Td><Input Type="File" Name="Filelist []" Size="50" /> Td> Tr>
  25. Table>
  26. <Input Type="Submit" Name="Submitfile" Value="Submit file" />
  27. Form>
  28. Body>
  29. Html>

PHP code for submitting dynamic multi-file upload:

 
 
  1. 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"<P>";
  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" P><Br><A Href="$ Postadd" Mce_href="$ Postadd">Return A> P>";
  28. }
  29. ?>
  30. Body>
  31. Html>

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


Upload File Code :! DOCTYPEhtmlPUBLIC "-// W3C // DTDXHTML1.0Transitional //" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "html xmlns =" http://www.w...

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.