I have also written many Image upload programs before, but none of them are short below. The simpler the program, the better, right? First, run the source code. you can copy it to your computer to run it ~
The code is as follows:
Multi-file Upload
// 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 ++;
}
}
?>
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.