Master teaches you PHP upload multiple pictures _php tutorial

Source: Internet
Author: User
When learning PHP, you may encounter PHP upload a number of picture problems, here will introduce PHP upload a number of pictures problem resolution, here to take out and share with you. Single picture upload is not complex, here is related to PHP upload a number of pictures and image format verification, to ensure that the upload must be a picture, to prevent uploading other files to the server.

The basic implementation algorithm is to use the form of an array, all the pictures submitted an array, the elements of the array to deal with each. PHP is really just a module function of Web server, so the security of Web server should be ensured first. Of course, the Web server to be secure and must be first to ensure that the system security, so far away, endless. PHP can be combined with a variety of Web servers, and this is just about Apache. It is highly recommended to install boot Apache in chroot mode, so that even if Apache and PHP and their scripts are compromised, only the system that is affected will not compromise the actual system. The following is the referenced content:

 
 
  1. PHP
  2. Picture Catalogue
  3. $ Img_dir = ".. /upload/";
  4. ... HTML display upload interface
  5. /* Image upload processing */
  6. Upload images to the server
  7. Initialize variables
  8. $ uploaded = 0 ;
  9. $ unuploaded = 0 ;
  10. Allow only five images to upload
  11. For ($i=0; $i<=5; $i + +)
  12. {
  13. Get information about the current picture
  14. $ Is_file =$_files[' imgfile ' [' name '] [$i];
  15. If the current picture is not empty
  16. if (!empty ($is _file))
  17. {
  18. Store information about the current picture in a variable
  19. $result [$i]=]
  20. < Trclass Trclass = td2align =center >
  21. < TD > ". $_files[' imgfile ' [' name '] [$i]." td >
  22. < TD > ". Round ($_files[' imgfile '] [' size '] [$i]/1024,2)." K td >
  23. < TD > ". $_files[' imgfile ' [' type '] [$i]." td >
  24. < TD > ";
  25. Determine if the type of the uploaded image is one of the jpg,gif,png,bmp and determine if the upload was successful
  26. If
  27. $_files[' imgfile ' [' type '] [$i]== "Image/pjpeg" | |
  28. $_files[' imgfile ' [' type '] [$i]== "Image/gif" | |
  29. $_files[' imgfile ' [' type '] [$i]== "Image/x-png" | |
  30. $_files[' imgfile ' [' type '] [$i]== "Image/bmp"
  31. )
  32. {
  33. If the uploaded file does not exist on the server
  34. if (!file_exists ($img _dir.$_files[' imgfile ' [' name '] [$i]))
  35. {
  36. Transfer the picture file from the Temp folder to the directory we specified to upload
  37. Move_uploaded_file ($_files[' imgfile '] [' tmp_name '] [$i],
  38. $img _dir.$_files[' imgfile ' [' name '] [$i]);
  39. $result [$i] . = "Success" ;
  40. $uploaded + +;
  41. }
  42. else//if the file already exists on the server
  43. {
  44. $result [$i] . = "File already exists" ;
  45. $unuploaded + +;
  46. Continue
  47. }
  48. }
  49. Else
  50. {
  51. $result [$i] . = "Failed" ;
  52. $unuploaded + +;
  53. }
  54. $result [$i] . = "" ;
  55. }//endif
  56. }//endfor
  57. If no pictures are selected
  58. if (empty ($result))
  59. {
  60. prompt_msg ("error message", "No pictures selected.") "," return to the previous step "," uploadimg.php? " Action = Upload ");
  61. Exit ();
  62. }
  63. Show all post-upload results
  64. echo " < tablecellpadding tablecellpadding = 4cellspacing = 1border = 0class = Tablewidth = 400align =left >
  65. < Trclass Trclass = navialign =center >
  66. < TD > file name td >
  67. < TD > size td >
  68. < TD > type td >
  69. < TD > Upload Results td >
  70. TR >
  71. ";
  72. foreach ($resultas $value)
  73. {
  74. Echo$value;
  75. }
  76. echo " < Trclass Trclass = TD1 >
  77. < Tdcolspan Tdcolspan = 4 > total uploads ". ($uploaded + $unuploaded). ", Success: $uploaded, failure:<fontcolorfontcolor= Red > $unuploaded font> td >
  78. TR >
  79. < Trclass Trclass = Navi >
  80. <TdcolspanTdcolspan=4align=center>[<AhrefAhref= ' Uploadimg.php?action=upload 'title= ' Continue uploading '>Continue uploading a > ]
    [<ahrefahref= ' image.php 'title= ' Browse Pictures '> View pictures a>] td>
  81. TR >
  82. Table >
  83. ";
  84. ?>

http://www.bkjia.com/PHPjc/446548.html www.bkjia.com true http://www.bkjia.com/PHPjc/446548.html techarticle When learning PHP, you may encounter PHP upload a number of picture problems, here will introduce PHP upload a number of pictures problem resolution, here to take out and share with you. The picture on the leaflet ...

  • 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.