Simple PHP multi-graph upload of small program code

Source: Internet
Author: User

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.

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.