First on the source code, you can copy to your computer to run ~
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> multi-File upload </title>
<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
Uploading file information
$img = $_files[' img '];
if ($img)
{
File storage directory, and this PHP file sibling
$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 succeeds, preview
if ($state)
{
echo "}
}
$i + +;
}
}
?>
</body>
Move_uploaded_file () function
The Move_uploaded_file () function moves the uploaded file to a new location. If successful, returns TRUE, otherwise returns false.
Usage: move_uploaded_file (file,newloc)
Parameter file, required. Specify the files to be moved.
Parameter newloc, required. Specify a new location for the file.
This function checks to make sure that files specified by file are valid uploads (that is, uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it is moved to the file specified by Newloc.
If file is not a legitimate upload file, no action occurs, Move_uploaded_file () returns false.
If file is a legitimate upload, but cannot be moved for some reason, Move_uploaded_file () will return false and a warning will be issued.
This check is particularly important if the uploaded file is likely to cause the content to be displayed to users or other users of the system.
Note: This function is only for files uploaded via HTTP POST.
Note: If the target file already exists, it will be overwritten.