First, run the source code. You can copy it to your computer to run it ~
Copy codeThe Code is as follows:
<Html>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Head>
<Title> Multifile upload </title>
</Head>
<Body>
<Form accept = "" method = "post" enctype = "multipart/form-data">
<Input type = "file" name = "img []"/> <br/>
<Input type = "file" name = "img []"/> <br/>
<Input type = "file" name = "img []"/> <br/>
<Input type = "file" name = "img []"/> <br/>
<Input type = "file" name = "img []"/> <br/>
<Input type = "file" name = "img []"/> <br/>
<Input type = "submit" name = "s"/> <br/>
</Form>
<? Php
// Upload File Information
$ Img = $ _ FILES ['img '];
If ($ img)
{
// File storage directory, which is the same as the PHP File
$ Dir = dirname (_ file __);
$ I = 0;
Foreach ($ img ['tmp _ name'] as $ value)
{
$ Filename = $ img ['name'] [$ I];
If ($ value)
{
$ Savepath = "$ dir \ $ filename ";
$ State = move_uploaded_file ($ value, $ savepath );
// If the upload is successful, preview
If ($ state)
{
Echo " ";
}
}
$ I ++;
}
}
?>
</Body>
</Html>
Move_uploaded_file () function
The move_uploaded_file () function moves the uploaded file to the new location. If yes, true is returned. Otherwise, false is returned.
Usage: move_uploaded_file (file, newloc)
Parameter file, required. Specifies the file to be moved.
Required. Specifies the new location of the file.
This function checks and ensures that the file specified by the file is a valid file to be uploaded (that is, the file is uploaded through the http post upload mechanism of PHP ). If the file is valid, it is moved to the file specified by newloc.
If the file is not a valid Upload file, no operation is performed. move_uploaded_file () returns false.
If the file is valid but cannot be moved for some reason, no operation will occur. move_uploaded_file () will return false, and a warning will be issued.
This check is especially important. If the uploaded file may display the content to the user or other users in the system.
Note: This function is only used for files uploaded through http post.
Note: If the target file already exists, it will be overwritten.