Experts teach you how to upload multiple images in PHP. When learning PHP, you may encounter the problem of uploading multiple images in PHP. here we will introduce the solution to the problem of uploading multiple images in PHP. here we will share it with you. When learning PHP on a single image, you may encounter the problem of uploading multiple images in PHP. here we will introduce the solution to the problem of uploading multiple images in PHP. I will share it with you here. Uploading a single image is not complex. this involves uploading multiple images in PHP and verifying the image format. This ensures that images are uploaded and other files are uploaded to the server.
The basic implementation algorithm uses arrays to submit an array of all images and process the elements of the array one by one. PHP is actually a module function of the Web server. Therefore, you must first ensure the security of the Web server. Of course, to ensure the security of Web servers, you must first ensure the system security. this is a long way to go and is endless. PHP can be combined with various Web servers. here we only discuss Apache. We strongly recommend that you install and start Apache in the form of chroot. in this way, even if Apache, PHP, and their scripts are prone to vulnerabilities, only the banned system will be affected and the actual system will not be harmed. Reference content is as follows:
- Php
-
- // Image directory
- $Img_dir="../Upload /";
- //...... Html display Upload interface
-
- /* Image Upload processing */
- // Upload the image to the server
- // Initialize the variable
-
- $Uploaded=0;
- $Unuploaded=0;
-
- // Only five images can be uploaded
-
- For ($I=0; $ I<= 5; $ I ++)
- {
- // Obtain the information of the current image
- $Is_file= $ _ FILES ['imgfile'] ['name'] [$ I];
- // If the current image is not empty
- If (! Empty ($ is_file ))
- {
- // Store the information of the current image in the variable
- $ Result [$ I] ="
- <TrclassTrclass=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 whether the type of the uploaded image is jpg, gif, png, or bmp, and whether the upload is 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 image file from the temporary folder to the directory we specified for Upload
- Move_uploaded_file ($ _ FILES ['imgfile'] ['tmp _ name'] [$ I],
- $ Img_dir. $ _ FILES ['imgfile'] ['name'] [$ I]);
- $ Result [$ I].="Successful";
- $ 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 image is selected
- If (empty ($ result ))
- {
- Prompt_msg ("error message", "No image is selected. "," Back to the previous step "," uploadimg. php?Action=Upload");
- Exit ();
- }
-
- // Display all uploaded results
- Echo"<TablecellpaddingTablecellpadding=4 cellspacing=1 border=0 class=Tablewidth=400 align= Left>
- <TrclassTrclass=Navialign= Center>
- <Td>File name Td>
- <Td>Size Td>
- <Td>Type Td>
- <Td>Upload result Td>
- Tr>
- ";
-
- Foreach ($ resultas $ value)
- {
- Echo $ value;
- }
-
- Echo"<TrclassTrclass=Td1>
- <TdcolspanTdcolspan=4>Upload ". ($ uploaded + $ unuploaded).", successful: $ uploaded, failed:<FontcolorFontcolor=Red>$ Unuploaded Font> Td>
- Tr>
- <TrclassTrclass=Navi>
- <TdcolspanTdcolspan=4 align= Center>[<AhrefAhref= 'Uploadimg. php? Action = upload'Title= 'Continue upload'>Continue Upload A>]
[<AhrefAhref= 'Image. php'Title= 'Browse image'>Browse images A>] Td>
- Tr>
- Table>
- ";
- ?>
Bytes. Single picture...