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:
- PHP
- Picture Catalogue
- $ Img_dir = ".. /upload/";
- ... HTML display upload interface
- /* Image upload processing */
- Upload images to the server
- Initialize variables
- $ uploaded = 0 ;
- $ unuploaded = 0 ;
- Allow only five images to upload
- For ($i=0; $i<=5; $i + +)
- {
- Get information about the current picture
- $ Is_file =$_files[' imgfile ' [' name '] [$i];
- If the current picture is not empty
- if (!empty ($is _file))
- {
- Store information about the current picture in a variable
- $result [$i]=]
- < Trclass Trclass = td2align =center >
- < TD > ". $_files[' imgfile ' [' name '] [$i]." td >
- < TD > ". Round ($_files[' imgfile '] [' size '] [$i]/1024,2)." K td >
- < TD > ". $_files[' imgfile ' [' type '] [$i]." td >
- < TD > ";
- Determine if the type of the uploaded image is one of the jpg,gif,png,bmp and determine if the upload was successful
- If
- $_files[' imgfile ' [' type '] [$i]== "Image/pjpeg" | |
- $_files[' imgfile ' [' type '] [$i]== "Image/gif" | |
- $_files[' imgfile ' [' type '] [$i]== "Image/x-png" | |
- $_files[' imgfile ' [' type '] [$i]== "Image/bmp"
- )
- {
- If the uploaded file does not exist on the server
- if (!file_exists ($img _dir.$_files[' imgfile ' [' name '] [$i]))
- {
- Transfer the picture file from the Temp folder to the directory we specified to upload
- Move_uploaded_file ($_files[' imgfile '] [' tmp_name '] [$i],
- $img _dir.$_files[' imgfile ' [' name '] [$i]);
- $result [$i] . = "Success" ;
- $uploaded + +;
- }
- else//if the file already exists on the server
- {
- $result [$i] . = "File already exists" ;
- $unuploaded + +;
- Continue
- }
- }
- Else
- {
- $result [$i] . = "Failed" ;
- $unuploaded + +;
- }
- $result [$i] . = "" ;
- }//endif
- }//endfor
- If no pictures are selected
- if (empty ($result))
- {
- prompt_msg ("error message", "No pictures selected.") "," return to the previous step "," uploadimg.php? " Action = Upload ");
- Exit ();
- }
- Show all post-upload results
- echo " < tablecellpadding tablecellpadding = 4cellspacing = 1border = 0class = Tablewidth = 400align =left >
- < Trclass Trclass = navialign =center >
- < TD > file name td >
- < TD > size td >
- < TD > type td >
- < TD > Upload Results td >
- TR >
- ";
- foreach ($resultas $value)
- {
- Echo$value;
- }
- echo " < Trclass Trclass = TD1 >
- < Tdcolspan Tdcolspan = 4 > total uploads ". ($uploaded + $unuploaded). ", Success: $uploaded, failure:<fontcolorfontcolor= Red > $unuploaded font> td >
- TR >
- < Trclass Trclass = Navi >
- <TdcolspanTdcolspan=4align=center>[<AhrefAhref= ' Uploadimg.php?action=upload 'title= ' Continue uploading '>Continue uploading a > ]
[<ahrefahref= ' image.php 'title= ' Browse Pictures '> View pictures a>] td>
- TR >
- Table >
- ";
- ?>
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 ...