Mini Program Simple PHP multi-image upload mini program code

WBOY
Release: 2016-07-29 08:46:13
Original
1010 people have browsed it

First go to the source code, you can copy it to your own computer and run it ~

Copy the code The code is as follows:



















// Upload file information
$img = $_FILES['img'];
if ($img)
{
//File storage directory, same level as this 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 "$filename ";
}
}
$i++;
}
}
?>



move_uploaded_file() function
move_uploaded_file() function will upload File movement to a new location. Returns true if successful, false otherwise.
Usage: move_uploaded_file(file,newloc)
Parameter file, required. Specifies the files to be moved.
Parameter newloc, required. Specifies the new location of the file.
This function checks and ensures that the file specified by file is a legal upload file (that is, uploaded through PHP's HTTP POST upload mechanism). If the file is legal, it is moved to the file specified by newloc.
If file is not a legal uploaded file, no operation will occur and move_uploaded_file() will return false.
If file is a valid uploaded file but cannot be moved for some reason, no action will occur and move_uploaded_file() will return false and a warning will be issued.
This kind of check is particularly important if the uploaded file may cause its content to be displayed to the user or other users of this system.
Note: This function is only used for files uploaded via HTTP POST.
Note: If the target file already exists, it will be overwritten.

The above introduces the applet, a simple PHP multi-image upload applet code, including the content of the applet. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template