Today, I made a little research on the Multi-image upload function and sorted out the following code to facilitate future use and communication.
1、upload.html page, that is, the file with input type = file:
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> </title>
</Head>
<Body>
<Form enctype = "multipart/form-data" action = "do_upload.php" method = "POST">
<! -- Enctype = "multipart/form-data" in the form indicates to set the MIME encoding of the form. By default, the encoding format is application/x-www-form-urlencoded and cannot be used for file upload. Only multipart/form-data can be used to completely transmit file data, perform the following operations. -->
<Fieldset>
<Legend> Image Upload </legend>
The first image <input name = "userfile" type = "file"> <br>
Figure 2 <input name = "userfile" type = "file"> <br>
Figure 3 <input name = "userfile" type = "file"> <br>
Figure 4 <input name = "userfile" type = "file"> <br>
Figure 5 <input name = "userfile" type = "file"> <br>
<! -- Transfer data in the form of an array -->
<Input type = "submit" value = "Send File">
</Fieldset>
</Form>
</Body>
</Html>
2. do_upload.php page, that is, the page for processing Multifile uploads:
Copy codeThe Code is as follows:
<? Php
// Global Array $ _ FILES
// $ _ FILES ['userfile'] ['tmp _ name'] location where the file is temporarily stored on the web Server
// $ _ FILES ['userfile'] ['name'] file name in the user's system
// $ _ FILES ['userfile'] ['SIZE'] File size in bytes
// $ _ FILES ['userfile'] ['type'] MIME type, text/plain, image/gif
// $ _ FILES ['userfile'] ['error'] error Code related to File Upload
?>
<? Php
// Use the for loop to obtain the transmitted data, which is a three-dimensional data.
For ($ I = 0; $ I <count ($ _ FILES ['userfile'] ['tmp _ name']); $ I ++)
{
$ Upfile = $ new_folder. "/". $ _ FILES ['userfile'] ['name'] [$ I]; // you can modify it as needed.
If (move_uploaded_file ($ _ FILES ['userfile'] ['tmp _ name'] [$ I], $ upfile )){
Echo "no.". ($ I + 1). "The image has been uploaded successfully. <br> ";
}
Else {
Echo "no." ($ I + 1). "Images cannot be uploaded <br> ";
}
}
?>