Simple PHP Multi-graphics upload small program code _php tips

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.